lib/tobox.rb in tobox-0.5.2 vs lib/tobox.rb in tobox-0.6.0
- old
+ new
@@ -32,9 +32,35 @@
def self.register_plugin(name, mod)
h = @plugins
h.synchronize { h[name] = mod }
end
end
+
+ # when using batch sizes higher than 1, this method can be used to signal multiple errors
+ # for a subset of the events which may have failed processing; these events are identified
+ # by the index inside the batch.
+ #
+ # on(:event_type) do |*events|
+ # successful, failed = handle_event_batch(events)
+ #
+ # deal_with_success(successful)
+ #
+ # batch_errors = failed.to_h do |failed_event|
+ # [
+ # events.index(failed_event),
+ # MyException.new("failed handling process batch")
+ # ]
+ # end
+ #
+ # Tobox.raise_batch_error(batch_errors)
+ # end
+ def self.raise_batch_errors(batch_errors)
+ unless batch_errors.respond_to?(:to_hash) && batch_errors.all? { |k, v| k.is_a?(Integer) && v.is_a?(Exception) }
+ raise "batch errors must be an array of index-to-exception tuples"
+ end
+
+ throw(:tobox_batch_errors, batch_errors.to_h)
+ end
end
require_relative "tobox/fetcher"
require_relative "tobox/worker"
require_relative "tobox/pool"