public
Last active

prune_workers_from_terminated_instance.rb

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9
module Resque
def self.unregister_workers_for_host(host)
Resque.workers.select{|worker| worker.id.split(':').first==host}.each(&:unregister_worker)
end
 
end
 
Resque.unregister_workers_for_host("ip-10-250-192-51")

Unregister resque workers for hosts that don't respond to pings:

worker_hosts = Resque.workers.map {|w| ip = w.id.split(":").first}.uniq
bad_hosts = worker_hosts.reject {|host| ip = host.gsub(/^ip-/, '').gsub('-', '.'); system "ping #{ip} -W 1 -c 1"}
Resque.workers.select {|w| bad_hosts.any? {|host| w.id.include?(host)}}.each(&:unregister_worker)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.