Cron Schedule Builder for Rails
Set the five fields, read the schedule back in plain English, and take away the three things a Rails app actually needs - the crontab line, the config/schedule.rb block, and the recurring job entry.
Your schedule
Every 5 minutes, every day.
Use this schedule in a Rails app
crontab
*/5 * * * * cd /var/www/app/current && bin/rails runner 'CleanupJob.perform_later'config/schedule.rb (whenever gem)
every 5.minutes do
runner "CleanupJob.perform_later"The whenever gem also takes a five field line verbatim, so anything the Ruby sugar will not express can be written out in full.
config/recurring.yml (Solid Queue and GoodJob)
production:
cleanup_job:
class: CleanupJob
schedule: "*/5 * * * *"
# GoodJob: config.good_job.cron = { cleanup_job: { cron: "*/5 * * * *", class: "CleanupJob" } }Field by field
0-59
0-23
1-31
1-12 or JAN-DEC
0-6 or SUN-SAT
Next five runs
No date in the next thirty years matches this schedule. A combination such as the 30th of February never comes round.
Everything runs in your browser. Nothing is uploaded.
The five fields a Rails schedule is built from
A crontab line is five fields separated by spaces, always in the same order: minute, hour, day of the month, month, day of the week. Minute runs 0 to 59, hour 0 to 23, day of the month 1 to 31, month 1 to 12, and day of the week 0 to 6 with Sunday also written as 7. A star stands for every value the field can hold, a comma lists values, a hyphen gives a range and a slash gives a step, so `*/15` in the minute field is a quarter past, half past, quarter to and on the hour. Month and day of the week also accept three letter names, so JAN and MON read the same as 1 and 1. Every scheduler in this list - crontab, the whenever gem, Solid Queue, GoodJob - agrees on those five fields, which is why one line is enough to describe a schedule to all of them.
What the whenever gem does with these fields
The whenever gem does not replace cron, it writes for it. You describe the schedule in Ruby in config/schedule.rb, and `whenever --update-crontab` compiles that file into the crontab entries for the deploying user, each one carrying the path, the bundler context and the environment that a hand written line so often forgets. The sugar covers the shapes a Rails app reaches for most - an interval such as `every 5.minutes`, a daily run with one or several times, a single weekday, the working week - and falls back to the raw five field line for anything else. The block above is generated from whichever of those your schedule fits.
Recurring jobs without a crontab: Solid Queue and GoodJob
Solid Queue ships with Rails 8 and reads its schedule from config/recurring.yml, keyed by environment, with a class or a command and a schedule string per task. GoodJob does the same through config.good_job.cron in an initializer, as a hash of job definitions. Both parse the schedule with fugit, which understands the five fields exactly as written here and also accepts a timezone after them, so a nightly job can be pinned to a real place rather than to whatever clock the box keeps. The practical difference from crontab is where a failure lands - a recurring task that raises is a failed job in the queue, with its backtrace and its retries, instead of a line of mail nobody reads.