Gem schedule “whenever”

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

Installation

$ gem install whenever

Or with Bundler in your Gemfile.

gem 'whenever', :require => false

 

Getting started

$ cd /apps/my-project
$ wheneverize .

This will create an initial config/schedule.rb file for you.

Show example code in page: https://github.com/javan/whenever

Notes:

– When add new schedule in schedule.rb file => Update schedule by:

whenever -i
OR
whenever --update-crontab

*** Remmember add RAILS_ENV=production or RAILS_ENV=development

– To show all schedule is active:

crontab -l

– To edit schedule was generated and is active:

crontab -e

edit and save.

Format when define schedule

Ex:

every '4 10 * * *' do
 rake "daily:save_diff"
end
* * * * * *
| | | | | |
| | | | | +-- Year              (range: 1900-3000)
| | | | +---- Day of the Week   (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month  (range: 1-31)
| +---------- Hour              (range: 0-23, 1 in our example)
+------------ Minute            (range: 0-59, 10 in our example)
Advertisements