Project

cron-table

0.0
The project is in a healthy, maintained state
Simple system to schedule recurring jobs for Rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 0.16

Runtime

~> 7.0
 Project Readme

CronTable

Basic cron-like system to schedule jobs

Setup

  1. Add cron-table gem
  2. Run rails app:cron_table:install:migrations
  3. Run rails db:migrate to apply migrations

Usage

  1. Add include CronTable::Schedule to the job
  2. Define cron schedule using crontable(every: <interval>)
  3. Use block if cron requires params, eg crontable(every: 1.day) { perform_later(Time.current) }

Interval specification

Use every to specify when cron should run. Allowed values include:

  1. Positive ActiveSupport::Duration like 1.hour, 2.days
  2. Predefined intervals
  • midnight
  • noon
  • beginning_of_hour
  1. Custom interval registered in CronTable.every, eg
  # config/initializers/cron_table.rb
  CronTable.every[:custom] = ->(context) { rand(1.hour..1.day).from_now }

Middlewares

Cron execution can be instrumented using middleware, eg

module CronTableInstrumentation
  def process(context)
    ElasticAPM.with_transaction(context.cron.key, "cron") { super }
  end
end
CronTable.register(CronTableInstrumentation)

License

The gem is available as open source under the terms of the MIT License.