javan /whenever

Cron jobs in Ruby

★ 8,848⑂ 714👁 107⑃ 308● 567▤ 5
RubyMITCreated 2009-02-16
下载:v1.1.4v1.1.4 ↓1.1.42026-10-21
-3
日增长
8,848
stars
714
forks
107
watchers
308
prs
567
issues
5
releases

README

Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs.

 Installation

sh
$ gem install whenever


Or with Bundler in your Gemfile.

ruby
gem 'whenever', require: false


 Getting started

sh
$ cd /apps/my-great-project
$ bundle exec wheneverize .


This will create an initial config/schedule.rb file for you (as long as the config folder is already present in your project).

 The whenever command

The whenever command will simply show you your schedule.rb file converted to cron syntax. It does not read or write your crontab file.

sh
$ cd /apps/my-great-project
$ bundle exec whenever


To write your crontab file for your jobs, execute this command:

sh
$ whenever --update-crontab


Other commonly used options include:
sh
$ whenever --user app  set a user as which to install the crontab
$ whenever --load-file config/my_schedule.rb  set the schedule file
$ whenever --crontab-command 'sudo crontab'  override the crontab command


 Note: If you run the whenever --update-crontab without passing the --user attribute, cron will be generated by the current user. This mean tasks that needs other user permission will fail.

You can list installed cron jobs using crontab -l.

Run whenever --help for a complete list of options for selecting the schedule to use, setting variables in the schedule, etc.

 Example schedule.rb file

ruby
every 3.hours do  1.minute 1.day 1.week 1.month 1.year is also supported
   the following tasks are run in parallel (not in sequence)
  runner "MyModel.some_process"
  rake "my:rake:task"
  command "/usr/bin/my_great_command"
end

every 3.hours, sequential: true do
   Jobs in this block that don't set their own sequence will default to run in the same sequence (not in parallel)
  runner "MyModel.some_process", halt_sequence_on_failure: true  If this job fails, subsequent jobs will not run (defaults to false)
  rake "my:rake:task"
  command "/usr/bin/my_great_command", sequence: nil  This job runs in parallel with other jobs that are not part of a sequence
  runner "MyModel.task_to_run_at_four_thirty_in_the_morning", sequence: 'other'  This job runs sequentially with other jobs in the sequence called 'other'
end

every 1.day, at: '4:30 am' do
  runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
end

every 1.day, at: ['4:30 am', '6:00 pm'] do
  runner "Mymodel.task_to_run_in_two_times_every_day"
end

every :hour do  Many shortcuts available: :hour, :day, :month, :year, :reboot
  runner "SomeModel.ladeeda"
end

every :sunday, at: '12pm' do  Use any day of the week or :weekend, :weekday
  runner "Task.do_something_great"
end

every '0 0 27-31  ' do
  command "echo 'you can use raw cron syntax too'"
end

 run this task only on servers with the :app role in Capistrano
 see Capistrano roles section below
every :day, at: '12:20am', roles: [:app] do
  rake "app_server:task"
end


 Define your own job types

Whenever ships with three pre-defined job types: command, runner, and rake. You can define 

Top issues

Latest release

v1.1.4 v1.1.4 2026-10-21
What's Changed
 Maintenance
 Don't ship tests in the gem by @sampokuokkanen in https://github.com/javan/whenever/pull/877

 New Contributors
 @sampokuokkanen made their first contribution in https://github.com/javan/whenever/pull/877

Full Changelog: https://github.com/javan/whenever/compare/v1.1.3...v1.1.4

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON