Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Pollable
- class << self
- def add_poller(*conditions, &blk)
- pollers << {
- :conditions => conditions,
- :poller =>
- Proc.new do |o|
- o.instance_eval &blk
- end
- }
- end
- def pollers
- @pollers ||= Array.new
- end
- end
- def poll
- self.class.pollers.each do |poller|
- poller[:poller].call(self)
- end
- end
- end
- class Device < Pollable
- add_poller({:every => 30.seconds, :if => {:icmp_responding => false}}, {:every => 5.minutes, :if => {:icmp_responding => true}}) do
- puts "Poll A #{@id}"
- end
- add_poller(:every => 5.minutes, :subscribe => {:icmp_responding => true}) do
- puts "Poll B #{@id}"
- end
- def initialize
- @id = 5
- end
- end
Add Comment
Please, Sign In to add comment