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

#each, #fetch, #find_job, #schedule

Methods inherited from SortedSet

#clear, #scan, #size

Constructor Details

#initializeDeadSet

Returns a new instance of DeadSet.


784
785
786
# File 'lib/sidekiq/api.rb', line 784

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


790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
# File 'lib/sidekiq/api.rb', line 790

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


812
813
814
# File 'lib/sidekiq/api.rb', line 812

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