-
-
Save svoop/12de6e3f7a447dc0e036ce1ca35d11ba to your computer and use it in GitHub Desktop.
Rake task for Delayed::Job to launch multiple monitored workers in a container context
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 :jobs do | |
desc "Start one or more monitored delayed_job workers (as per environment)" | |
task :workmulti => :environment do | |
daemons_count = Rails.env.production? ? 5 : 1 | |
pids = [] | |
loop do | |
pids.delete_if { !(Process.kill(0, _1) rescue false) } | |
(daemons_count - pids.count).times do | |
pids << fork { Delayed::Worker.new.start } | |
Process.detach pids.last | |
end | |
sleep 60 | |
end | |
ensure | |
pids.each { Process.kill('TERM', _1) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment