Object
The tracker service is used by the "listen" expression. This services sees all the msg processed by a worker and triggers any listener interested in a particular msg.
Look at the ListenExpression for more details.
# File lib/ruote/evt/tracker.rb, line 37 def initialize (context) @context = context if @context.worker # # this is a worker context, DO log # @context.worker.subscribe(:all, self) #else # # this is not a worker context, no notifications. BUT # honour calls to add_tracker/remove_tracker # end end
Adds a tracker (usually when a 'listen' expression gets applied).
# File lib/ruote/evt/tracker.rb, line 82 def add_tracker (wfid, action, fei, conditions, msg, doc=nil) doc ||= @context.storage.get_trackers doc['trackers'][Ruote.to_storage_id(fei)] = { 'wfid' => wfid, 'action' => action, 'fei' => fei, 'conditions' => conditions, 'msg' => msg } r = @context.storage.put(doc) add_tracker(wfid, action, fei, msg, r) if r # the put failed, have to redo the work end
The worker passes all the messages it has to process to the tracker via this method.
# File lib/ruote/evt/tracker.rb, line 57 def notify (msg) doc = @context.storage.get_trackers doc['trackers'].values.each do |tracker| t_wfid = tracker['wfid'] t_action = tracker['action'] m_wfid = msg['wfid'] || (msg['fei']['wfid'] rescue nil) next if t_wfid && t_wfid != m_wfid next if t_action && t_action != msg['action'] next unless does_match?(msg, tracker['conditions']) m = tracker['msg'] @context.storage.put_msg( m.delete('action'), m.merge!('workitem' => msg['workitem'])) end end
Removes a tracker (usually when a 'listen' expression replies to its parent expression or is cancelled).
# File lib/ruote/evt/tracker.rb, line 102 def remove_tracker (fei, doc=nil) doc ||= @context.storage.get_trackers doc['trackers'].delete(Ruote.to_storage_id(fei)) r = @context.storage.put(doc) remove_tracker(fei, r) if r # the put failed, have to redo the work end
Generated with the Darkfish Rdoc Generator 2.