Skip to content

Instantly share code, notes, and snippets.

@skord
Created February 25, 2012 20:23
Show Gist options
  • Save skord/1910420 to your computer and use it in GitHub Desktop.
Save skord/1910420 to your computer and use it in GitHub Desktop.
pinger
def self.ping_server
EM.synchrony do
@start_time = Time.now
r = Redis.new
ips = r.smembers('not_pinged')
concurrency = 500
EM::Synchrony::Iterator.new(ips, concurrency).map do |ip, iter|
ip = ip_to_icmp_object(ip_to_s(ip))
ip.failures_required = 3
ip.on_success {|host| ip.stop ; Fiber.new {r.smove 'not_pinged', 'up', ip_to_i(host)}.resume ; iter.return}
ip.on_failure {|host| ip.stop ; Fiber.new {r.smove 'not_pinged', 'down', ip_to_i(host)}.resume ; iter.return}
ip.schedule
end
p Time.now - @start_time
EM.stop
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment