-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
#662Can whenever take timezone from config?30 comments · 2016-09-14#500Whenever tasks not running on Rails 419 comments · 2014-10-26#665Whenever gem (cron job) not executing rake task, Rails 415 comments · 2016-10-09#567crontab doesn't update after cap deploy10 comments · 2015-06-27#679whenever error "Bundler::GemNotFound: Your bundle is locked to aasm"8 comments · 2016-12-16#612cap development whenever:update_crontab silently succeeds, does nothing7 comments · 2016-04-21#734Capistrano deploy, sporadic duplicate cronjob entries6 comments · 2017-12-12#703Whenever with capistrano should use symlinked `/current/` instead of `/app_revision/` folder in crontab6 comments · 2017-06-10
Latest release
v1.1.4 v1.1.4 2026-10-21What'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