Class: Sidekiq::DeadSet

Inherits:
JobSet show all
Defined in:
lib/sidekiq/api.rb

Overview

The set of dead jobs within Sidekiq. Dead jobs have failed all of their retries and are helding in this set pending some sort of manual fix. They will be removed after 6 months (dead_timeout) if not.

Instance Attribute Summary

Attributes inherited from SortedSet

#Name, #name

Instance Method Summary collapse

Methods inherited from JobSet

#delete_by_jid, #delete_by_value, #each, #fetch, #find_job, #schedule

Methods inherited from SortedSet

#as_json, #clear, #scan, #size

Constructor Details

#initializeDeadSet

Returns a new instance of DeadSet.



810
811
812
# File 'lib/sidekiq/api.rb', line 810

def initialize
  super("dead")
end

Instance Method Details

#kill(message, opts = {}) ⇒ Object

Add the given job to the Dead set.

Parameters:

  • message (String)

    the job data as JSON



816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
# File 'lib/sidekiq/api.rb', line 816

def kill(message, opts = {})
  now = Time.now.to_f
  Sidekiq.redis do |conn|
    conn.multi do |transaction|
      transaction.zadd(name, now.to_s, message)
      transaction.zremrangebyscore(name, "-inf", now - Sidekiq::Config::DEFAULTS[:dead_timeout_in_seconds])
      transaction.zremrangebyrank(name, 0, - Sidekiq::Config::DEFAULTS[:dead_max_jobs])
    end
  end

  if opts[:notify_failure] != false
    job = Sidekiq.load_json(message)
    r = RuntimeError.new("Job killed by API")
    r.set_backtrace(caller)
    Sidekiq.default_configuration.death_handlers.each do |handle|
      handle.call(job, r)
    end
  end
  true
end

#retry_allObject

Enqueue all dead jobs



838
839
840
# File 'lib/sidekiq/api.rb', line 838

def retry_all
  each(&:retry) while size > 0
end