lib/tobox/worker.rb in tobox-0.6.1 vs lib/tobox/worker.rb in tobox-0.7.0

- old
+ new

@@ -9,13 +9,17 @@ @wait_for_events_delay = configuration[:wait_for_events_delay] @handlers = configuration.handlers || {} @fetcher = configuration.fetcher_class.new(label, configuration) @finished = false - return unless (message_to_arguments = configuration.arguments_handler) + if (message_to_arguments = configuration.arguments_handler) + define_singleton_method(:message_to_arguments, &message_to_arguments) + end - define_singleton_method(:message_to_arguments, &message_to_arguments) + Array(configuration.lifecycle_events[:start_worker]).each do |hd| + hd.call(self) + end end def finished? @finished end @@ -45,10 +49,14 @@ end end return if @finished - sleep(@wait_for_events_delay) if sum_fetched_events.zero? + wait_for_work if sum_fetched_events.zero? + end + + def wait_for_work + sleep(@wait_for_events_delay) end def message_to_arguments(event) event end