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.



683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
# File 'lib/resque/worker.rb', line 683

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