Method: Resque::Worker#unregister_worker

Defined in:
lib/resque/worker.rb

#unregister_worker(exception = nil) ⇒ Object

Unregisters ourself as a worker. Useful when shutting down.



720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
# File 'lib/resque/worker.rb', line 720

def unregister_worker(exception = nil)
  # If we're still processing a job, make sure it gets logged as a
  # failure.
  if (hash = processing) && !hash.empty?
    job = Job.new(hash['queue'], hash['payload'])
    # Ensure the proper worker is attached to this job, even if
    # it's not the precise instance that died.
    job.worker = self
    begin
      job.fail(exception || DirtyExit.new("Job still being processed"))
    rescue RuntimeError => e
      log_with_severity :error, e.message
    end
  end

  kill_background_threads

  data_store.unregister_worker(self) do |**opts|
    Stat.clear("processed:#{self}", **opts)
    Stat.clear("failed:#{self}",    **opts)
  end
rescue Exception => exception_while_unregistering
  message = exception_while_unregistering.message
  if exception
    message += "\nOriginal Exception (#{exception.class}): #{exception.message}"
    message += "\n  #{exception.backtrace.join("  \n")}" if exception.backtrace
  end
  fail(exception_while_unregistering.class,
       message,
       exception_while_unregistering.backtrace)
end