lib/ruote/log/default_history.rb in ruote-2.3.0.1 vs lib/ruote/log/default_history.rb in ruote-2.3.0.2

- old
+ new

@@ -1,7 +1,7 @@ #-- -# Copyright (c) 2005-2012, John Mettraux, jmettraux@gmail.com +# Copyright (c) 2005-2013, 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 @@ -31,16 +31,18 @@ # # This class includes Enumerable. # # NOTE: # - # this default history is worthless when there are multiple workers. + # 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. + # This can be changed by passing a 'history_max_size' option to the storage + # when initializing ruote ('history_max_size' => 0) is acceptable. # class DefaultHistory include Enumerable @@ -50,10 +52,12 @@ def initialize(context, options={}) @context = context @options = options + @max_size = context['history_max_size'] || DEFAULT_MAX_SIZE + @history = [] end # Returns all the msgs (events), most recent one is last. # @@ -120,17 +124,27 @@ # This method is called by the worker via the context. Successfully # processed msgs are passed here. # def on_msg(msg) + return if @max_size < 1 + msg = Ruote.fulldup(msg) msg['seen_at'] = Ruote.now_to_utc_s @history << msg - while (@history.size > (@options[:max_size] || DEFAULT_MAX_SIZE)) do + while (@history.size > @max_size) do @history.shift end + + rescue => e + + $stderr.puts '>' + '-' * 79 + $stderr.puts "#{self.class} issue, skipping" + $stderr.puts e.inspect + $stderr.puts e.backtrace[0, 2] + $stderr.puts '<' + '-' * 79 end end end