lib/ruote/evt/tracker.rb in ruote-2.1.9 vs lib/ruote/evt/tracker.rb in ruote-2.1.10
- old
+ new
@@ -23,10 +23,17 @@
#++
module Ruote
+ #
+ # 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.
+ #
class Tracker
def initialize (context)
@context = context
@@ -42,10 +49,13 @@
# honour calls to add_tracker/remove_tracker
#
end
end
+ # The worker passes all the messages it has to process to the tracker via
+ # this method.
+ #
def notify (msg)
doc = @context.storage.get_trackers
doc['trackers'].values.each do |tracker|
@@ -65,20 +75,12 @@
m.delete('action'),
m.merge!('workitem' => msg['workitem']))
end
end
- def does_match? (msg, conditions)
-
- conditions.each do |k, v|
- val = msg[k]
- return false unless val && val.match(v)
- end
-
- true
- end
-
+ # Adds a tracker (usually when a 'listen' expression gets applied).
+ #
def add_tracker (wfid, action, fei, conditions, msg, doc=nil)
doc ||= @context.storage.get_trackers
doc['trackers'][Ruote.to_storage_id(fei)] =
@@ -92,19 +94,34 @@
add_tracker(wfid, action, fei, msg, r) if r
# the put failed, have to redo the work
end
+ # Removes a tracker (usually when a 'listen' expression replies to its
+ # parent expression or is cancelled).
+ #
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
+
+ protected
+
+ def does_match? (msg, conditions)
+
+ conditions.each do |k, v|
+ val = msg[k]
+ return false unless val && val.match(v)
+ end
+
+ true
end
end
end