Created
January 24, 2017 22:06
-
-
Save kstevens715/004527a77b9b286f830a937364fb5856 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
desc 'Determine if Resque is Alive or not' | |
task :liveness, [:queue_name] => [:environment] do |_task, args| | |
Resque.workers.select { |w| w.hostname == Socket.gethostname }.each do |worker| | |
begin | |
Process.kill(0, worker.pid) | |
rescue Errno::ESRCH | |
puts "Dead: Resque process with pid #{worker.pid} should exist, but cannot be found." | |
exit 1 | |
end | |
run_at = worker.job["run_at"] | |
if run_at | |
now = DateTime.now.strftime("%s").to_i | |
run_at = DateTime.parse(run_at).strftime("%s").to_i | |
diff = (now - run_at) | |
if diff > 300 | |
puts "Dead: A worker job has been running for #{diff} seconds" | |
exit 1 | |
end | |
end | |
end | |
puts "Alive" | |
end |
Might want to check the worker_pids to see if they exist too.
How about making a class out this task so we can write test around them (mostly for documenting how we are figuring out 'liveness')?
Some more ideas on deducing Resque worker states:
https://github.com/resque/resque-web/blob/master/app/views/resque_web/workers/show.html.erb
Yeah @devdude we were chatting about that on hipchat, something like this?
https://gist.github.com/bloodycelt/28d691e2c4d8e9d41eb7aabcc109f088
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.