Skip to content

Instantly share code, notes, and snippets.

@afriqs
Created January 17, 2012 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afriqs/1626611 to your computer and use it in GitHub Desktop.
Save afriqs/1626611 to your computer and use it in GitHub Desktop.
Rake task to restart delayed_job_monitor if app not in maintenance mode
# Workers are watched by built-in delayed_job_monitor
# Use [bundle exec] rake jobs:restart to restart delayed_job_monitor
# * if app in maintenance mode (cf. maintenance.html), will do nothing
# * else if delayed_job_monitor yet running, will do nothing
# * else will restart delayed_job_monitor
# Can be used via a cron, for example :
# 15 * * * * RAILS_ENV=testing bundle exec rake jobs:restart
namespace :jobs do
desc "Restart delayed_job_monitor if no worker yet running"
task :restart do
maintenance_file = Rails.root + 'public/system/maintenance.html'
unless maintenance_file.exist?
cmd = "#{Rails.root}/script/delayed_job"
args = ["start", "-m"]
exec cmd, *args
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment