Guest User

Untitled

a guest
Jun 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. class Pollable
  2. class << self
  3. def add_poller(*conditions, &blk)
  4. pollers << {
  5. :conditions => conditions,
  6. :poller =>
  7. Proc.new do |o|
  8. o.instance_eval &blk
  9. end
  10. }
  11. end
  12.  
  13. def pollers
  14. @pollers ||= Array.new
  15. end
  16. end
  17.  
  18. def poll
  19. self.class.pollers.each do |poller|
  20. poller[:poller].call(self)
  21. end
  22. end
  23. end
  24.  
  25. class Device < Pollable
  26. add_poller({:every => 30.seconds, :if => {:icmp_responding => false}}, {:every => 5.minutes, :if => {:icmp_responding => true}}) do
  27. puts "Poll A #{@id}"
  28. end
  29.  
  30. add_poller(:every => 5.minutes, :subscribe => {:icmp_responding => true}) do
  31. puts "Poll B #{@id}"
  32. end
  33.  
  34. def initialize
  35. @id = 5
  36. end
  37. end
Add Comment
Please, Sign In to add comment