My rails app is deployed to several machines. I need each machine to run different cron jobs (it will be a disaster if they all run the job). How do i tell my script which machine it is currently on?
I am using the whenever gem, and i am thinking of adding the condition in the schedule.rb
Example:
My deploy/production.rb
role :memcache, "123.compute-1.amazonaws.com"
role :web, "456.compute-1.amazonaws.com"
role :db, "789.amazonaws.com"
role :misc, "789.amazonaws.com"
What I need to do:
if machine is db, email report every day on db capacity
if machine is xxx, do xxx...
Just had to do a lot of hunting and experimenting but I think I figured out how to accomplish this. Create separate config files for each role/server that you need a crontab on. Then only define the desired tasks in each config file. Finally, something like this in your deploy.rb:
You can set up capistrano tasks to only run for specific roles (I assume you are using capistrano from the
role
calls).For example: