Prevent “whenever” creating separate cron job on each deployment

I am using whenever gem for handling cron job in a Ruby on Rails application. It’s fantastic because of it’s very easy DSL to create tasks and schedule it. It will do all the dirty works to update crontab and run your task periodically as per your definition.

However, I ran into one problem that upon each deploy, whenever was creating a separate item in crontab. So when I’ve tried to check cron jobs (crontab -e), I see there are so many tasks.

It was doing this because I didn’t have :application param set in my capistrano settings (deploy.rb). Whenever depends on this name to match the existing names and update it. So all you need is to set application to your deploy.rb file.

set :application, 'your-fancy-app'

That should solve the problem. However, you need to manually cleanup current cronjob as it won’t update the current mess.