Skip to content

Instantly share code, notes, and snippets.

@kbaum
Created March 29, 2011 12:12
Show Gist options
  • Save kbaum/892247 to your computer and use it in GitHub Desktop.
Save kbaum/892247 to your computer and use it in GitHub Desktop.
prune_workers_from_terminated_instance.rb
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")
@mtalcott
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment