BC00
BC00

Reputation: 1639

Multiple schedule.rb files with whenever gem

Is it possible to have multiple schedule.rb files when using the whenever gem in rails to setup cron jobs? I am looking to have a regular schedule.rb file and also a reports_schedule.rb file that is going to be deployed to a different server and it has its own specific reports environment.

How does whenever use the schedule.rb file? Is this possible?

Upvotes: 2

Views: 1177

Answers (2)

Chris Taggart
Chris Taggart

Reputation: 111

Not sure whether this was added after the question was asked, but you seem to be able to do role-based scheduling now: See README at https://github.com/javan/whenever

Upvotes: 1

Joshua
Joshua

Reputation: 2109

It looks like it is possible if a bit ugly. Looking at the source code on job_list.rb:25 whenever just does an instance eval. So you can do something like the following.

schedule.rb

#Load reporting schedules
instance_eval(File.read('reporting_schedule.rb'), 'reporting_schedule.rb')

# All your regular jobs
# ...

reporting_schedule.rb

#Need some way to know if you are on the reporting server
if `hostname` =~ /reporting_server/
  # All your reporting jobs
  # ...
end

Worked for me doing some quick tests with the whenever command. Have not tried using it in a deploy though.

Upvotes: 1

Related Questions