lib/backburner/worker.rb in backburner-0.3.3 vs lib/backburner/worker.rb in backburner-0.3.4

- old
+ new

@@ -59,10 +59,11 @@ # # @example # Worker.new(['test.job']) def initialize(tube_names=nil) @tube_names = self.process_tube_names(tube_names) + register_signal_handlers! end # Starts processing ready jobs indefinitely. # Primary way to consume and process jobs in specified tubes. # @@ -85,10 +86,16 @@ # def prepare raise NotImplementedError end + # Triggers this worker to shutdown + def shutdown + log_info 'Worker exiting...' + Kernel.exit! + end + # Processes tube_names given tube_names array. # Should return normalized tube_names as an array of strings. # # @example # process_tube_names([['foo'], ['bar']]) @@ -163,8 +170,14 @@ tube_names = tube_names.first if tube_names && tube_names.size == 1 && tube_names.first.is_a?(Array) tube_names = Array(tube_names).compact if tube_names && Array(tube_names).compact.size > 0 tube_names = nil if tube_names && tube_names.compact.empty? tube_names ||= Backburner.default_queues.any? ? Backburner.default_queues : all_existing_queues Array(tube_names) + end + + # Registers signal handlers TERM and INT to trigger + def register_signal_handlers! + trap('TERM') { shutdown } + trap('INT') { shutdown } end end # Worker end # Backburner \ No newline at end of file