lib/ruote/log/default_history.rb in ruote-2.2.0 vs lib/ruote/log/default_history.rb in ruote-2.3.0
- old
+ new
@@ -1,7 +1,7 @@
#--
-# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
+# Copyright (c) 2005-2012, John Mettraux, jmettraux@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -27,36 +27,50 @@
#
# A default history implementation, only keeps the most recent stuff
# in memory.
#
- # NOTE : this default history is useless when there are multiple workers.
- # It only keeps track of the 'local' worker if there is one present.
+ # This class includes Enumerable.
#
+ # NOTE:
+ #
+ # this default history is worthless when there are multiple workers.
+ # It only keeps track of the msgs processed by the worker in the same
+ # context. Msgs processed by other workers (in different Ruby runtimes) are
+ # not seen (they are tracked by the DefaultHistory next to those workers).
+ #
+ # By default, this history keeps track of the latest 1'000 msgs.
+ #
class DefaultHistory
+ include Enumerable
+
DATE_REGEX = /!(\d{4}-\d{2}-\d{2})!/
DEFAULT_MAX_SIZE = 1000
def initialize(context, options={})
@context = context
@options = options
@history = []
-
- @context.worker.subscribe(:all, self) if @context.worker
- # only care about logging if there is a worker present
end
# Returns all the msgs (events), most recent one is last.
#
def all
@history
end
+ # Enabling Enumerable...
+ #
+ def each(&block)
+
+ @history.each(&block)
+ end
+
# Returns all the wfids for which some piece of history is kept.
#
def wfids
@history.collect { |msg|
@@ -101,13 +115,13 @@
def clear!
@history.clear
end
- # This is the method called by the workqueue. Incoming engine events
- # are 'processed' here.
+ # This method is called by the worker via the context. Successfully
+ # processed msgs are passed here.
#
- def notify(msg)
+ def on_msg(msg)
msg = Ruote.fulldup(msg)
msg['seen_at'] = Ruote.now_to_utc_s
@history << msg