lib/chicanery.rb in chicanery-0.0.2 vs lib/chicanery.rb in chicanery-0.0.3

- old
+ new

@@ -7,22 +7,27 @@ include Persistence include Servers include Handlers include StateComparison - VERSION = "0.0.2" + VERSION = "0.0.3" def execute *args load args.shift - previous_state = restore - current_state = { - servers: {} - } - servers.each do |server| - current_jobs = server.jobs - compare_jobs current_jobs, previous_state[:servers][server.name] if previous_state[:servers] - current_state[:servers][server.name] = current_jobs + poll_period = args.shift + loop do + previous_state = restore + current_state = { + servers: {} + } + servers.each do |server| + current_jobs = server.jobs + compare_jobs current_jobs, previous_state[:servers][server.name] if previous_state[:servers] + current_state[:servers][server.name] = current_jobs + end + run_handlers.each {|handler| handler.call current_state } + persist current_state + exit unless poll_period + sleep poll_period.to_i end - run_handlers.each {|handler| handler.call current_state } - persist current_state end end \ No newline at end of file