0
@@ -14,19 +14,32 @@ module God
0
- self.mutex = M
utex.new
0
+ self.mutex = M
onitor.new
0
- item = self.queue.pop rescue nil
0
- Timer.queue << TimerEvent.new(item.condition, item.condition.interval)
0
- sleep 0.25 if self.queue.empty?
0
+ event = self.queue.pop rescue nil
0
+ self.mutex.synchronize do
0
+ self.handle_poll(event.condition, event.phase)
0
+ when EventCondition, TriggerCondition
0
+ self.handle_event(event.condition)
0
+ # Timer.queue << TimerEvent.new(item.condition, item.condition.interval)
0
+ sleep 0.25 if self.queue.empty?
0
+ message = format("Unhandled exception (%s): %s\n%s",
0
+ e.class, e.message, e.backtrace.join("\n"))
0
+ applog(nil, :fatal, message)
0
@@ -76,18 +89,18 @@ module God
0
# +phase+ is the phase of the Watch at the time the condition was scheduled
0
- def self.trigger(condition, phase = nil)
0
- self.queue << [condition, phase]
0
- # self.mutex.synchronize do
0
- # self.handle_poll(condition, phase)
0
- # when EventCondition, TriggerCondition
0
- # self.handle_event(condition)
0
+ # def self.trigger(condition, phase = nil)
0
+ # self.queue << [condition, phase]
0
+ # self.mutex.synchronize do
0
+ # self.handle_poll(condition, phase)
0
+ # when EventCondition, TriggerCondition
0
+ # self.handle_event(condition)
0
@@ -98,81 +111,59 @@ module God
0
def self.handle_poll(condition, phase)
0
- # # Timer.get.schedule(condition)
0
- # metric = self.directory[condition]
0
- # # it's possible that the timer will trigger an event before it can be cleared
0
- # # by an exiting metric, in which case it should be ignored
0
- # return if metric.nil?
0
- # watch = metric.watch
0
- # # watch.mutex.synchronize do
0
- # # ensure this condition is still active when we finally get the mutex
0
- # if self.directory[condition] && phase == watch.phase
0
- # # result = condition.test
0
- # # messages = self.log(watch, metric, condition, result)
0
- # # if condition.notify && self.trigger?(metric, result)
0
- # # self.notify(condition, messages.last)
0
- # # # get the destination
0
- # # if result && condition.transition
0
- # # # condition override
0
- # # condition.transition
0
- # # metric.destination && metric.destination[result]
0
- # # # transition or reschedule
0
- # # rescue EventRegistrationFailedError
0
- # # msg = watch.name + ' Event registration failed, moving back to previous state'
0
- # # applog(watch, :info, msg)
0
- # # dest = watch.state
0
- # # Timer.get.schedule(condition)
0
- # Timer.get.schedule(condition)
0
- # rescue Exception => e
0
- # message = format("Unhandled exception (%s): %s\n%s",
0
- # e.class, e.message, e.backtrace.join("\n"))
0
- # applog(nil, :fatal, message)
0
+ metric = self.directory[condition]
0
- # Timer.get.schedule(condition)
0
+ # it's possible that the timer will trigger an event before it can be cleared
0
+ # by an exiting metric, in which case it should be ignored
0
-
# Timer.get.schedule(condition)0
- # Thread.list.each {|t| p t}
0
+ watch.mutex.synchronize do
0
+ # ensure this condition is still active when we finally get the mutex
0
+ if self.directory[condition] && phase == watch.phase
0
+ result = condition.test
0
+ messages = self.log(watch, metric, condition, result)
0
+ if condition.notify && self.trigger?(metric, result)
0
+ self.notify(condition, messages.last)
0
+ # # get the destination
0
+ # if result && condition.transition
0
+ # # condition override
0
+ # condition.transition
0
+ # metric.destination && metric.destination[result]
0
+ # # transition or reschedule
0
+ # rescue EventRegistrationFailedError
0
+ # msg = watch.name + ' Event registration failed, moving back to previous state'
0
+ # applog(watch, :info, msg)
0
+ Timer.queue << TimerEvent.new(condition, condition.interval)
0
# Asynchronously evaluate and handle the given event condition. Handles logging
Comments
No one has commented yet.