Our old solution for cronjobs, the "craken" plugin, is no longer maintained and does not work on Rails 3.2+.
We will instead use the whenever gem Show archive.org snapshot .
"Whenever" works just like "craken", by putting your rake tasks into the server's cron table. Everything seems to work just like we need it.
Add "whenever" to your Gemfile
:
group :deploy do
gem 'whenever', require: false
end
Add it to your config/deploy.rb
:
For Capistrano 2
set :application, 'PROJECT_NAME' # might be already set
set :whenever_command, "bundle exec whenever"
require 'whenever/capistrano'
Note that "whenever" will not use a :cron
role, but instead default to run cronjobs on the :db
server. That's just fine for us.
For Capistrano 3
set :application, 'PROJECT_NAME' # might be already set
set :whenever_roles , [:cron]
set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" }
Note that "whenever" will now use a :cron
role for all whenever tasks without a specific role provided in the attribute roles:
Add to your Capfile
(For Capistrano 3 only):
require 'whenever/capistrano'
Run b wheneverize
.
Edit config/schedule.rb
, for example
every 15.minutes, roles: [:cron] do
rake "makandra_de_website:update_tweet_cache"
end
You can check the crontab that would be written by running b whenever
. This does not change anything.
Do all of the above, and also
config/deploy.rb
.vendor/plugins/craken
.lib/tasks/craken.rb
. If so, delete that, too.config/craken/raketab
to config/schedule.rb
. Then delete the first file.crontab -e
. Remove the lines added by "craken" (they are clearly marked by a comment).