class Sidekiq::DeadSet

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.

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/sidekiq/api.rb, line 827
def initialize
  super("dead")
end

Public Instance Methods

kill(message, opts = {}) click to toggle source

Add the given job to the Dead set. @param message [String] the job data as JSON @option opts [Boolean] :notify_failure (true) Whether death handlers should be called @option opts [Boolean] :trim (true) Whether Sidekiq should trim the structure to keep it within configuration @option opts [Exception] :ex (RuntimeError) An exception to pass to the death handlers

# File lib/sidekiq/api.rb, line 848
def kill(message, opts = {})
  now = Time.now.to_f
  Sidekiq.redis do |conn|
    conn.zadd(name, now.to_s, message)
  end

  trim if opts[:trim] != false

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

Trim dead jobs which are over our storage limits

# File lib/sidekiq/api.rb, line 832
def trim
  hash = Sidekiq.default_configuration
  now = Time.now.to_f
  Sidekiq.redis do |conn|
    conn.multi do |transaction|
      transaction.zremrangebyscore(name, "-inf", now - hash[:dead_timeout_in_seconds])
      transaction.zremrangebyrank(name, 0, - hash[:dead_max_jobs])
    end
  end
end