-
-
Save Schniz/6685336 to your computer and use it in GitHub Desktop.
Files for using capistrano and resque.
some shell magic for killin those resque workers. pay attention to the `w.stop` stuff - it should kill all the resque proccesses (!!) when the god stops it. yeah.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :god do | |
desc "Hot-reload God configuration for the new release Resque worker" | |
task :reload_release do | |
run "cd #{release_path} && god && god load config/resque.god && god restart resque" | |
end | |
desc "Hot-reload God configuration for the current release Resque worker" | |
task :reload_current do | |
run "cd #{current_path} && god && god load config/resque.god && god restart resque" | |
end | |
desc "Terminates god :(" | |
task :terminate do | |
run "god terminate" | |
end | |
end | |
namespace :resque do | |
desc "Kills all the resque workers" | |
task :kill_all do | |
run "ps aux | grep resque | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RESQUE_WORKER_COUNT = ENV['RESQUE_WORKER_COUNT'] || 1 | |
RESQUE_RAILS_ENV = ENV['RAILS_ENV'] || 'production' | |
RESQUE_GEMFILE = ENV['RESQUE_GEMFILE'] || '/var/www/myapp/current/Gemfile' | |
God.watch do |w| | |
w.name = 'resque' | |
w.interval = 30.seconds | |
w.env = { 'RAILS_ENV' => RESQUE_RAILS_ENV, 'COUNT' => RESQUE_WORKER_COUNT.to_s, 'QUEUE' => '*', 'GEMFILE' => RESQUE_GEMFILE } | |
w.dir = File.expand_path(File.join(File.dirname(__FILE__),'..')) | |
w.start = "bundle exec rake resque:workers" | |
w.start_grace = 10.seconds | |
w.stop = "ps aux | grep resque | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill" | |
w.log = File.expand_path(File.join(File.dirname(__FILE__), '../../../shared/','log','resque-worker.log')) | |
# restart if memory gets too high | |
w.transition(:up, :restart) do |on| | |
on.condition(:memory_usage) do |c| | |
c.above = 100.megabytes | |
c.times = 2 | |
end | |
end | |
# determine the state on startup | |
w.transition(:init, { true => :up, false => :start }) do |on| | |
on.condition(:process_running) do |c| | |
c.running = true | |
end | |
end | |
# determine when process has finished starting | |
w.transition([:start, :restart], :up) do |on| | |
on.condition(:process_running) do |c| | |
c.running = true | |
c.interval = 5.seconds | |
end | |
# failsafe | |
on.condition(:tries) do |c| | |
c.times = 5 | |
c.transition = :start | |
c.interval = 5.seconds | |
end | |
end | |
# start if process is not running | |
w.transition(:up, :start) do |on| | |
on.condition(:process_running) do |c| | |
c.running = false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment