Class: Sidekiq::DeadSet

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

Overview

Allows enumeration of dead jobs within Sidekiq.

Instance Attribute Summary

Attributes inherited from SortedSet

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from JobSet

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

Methods inherited from SortedSet

#clear, #scan, #size

Constructor Details

#initializeDeadSet

Returns a new instance of DeadSet.


710
711
712
# File 'lib/sidekiq/api.rb', line 710

def initialize
  super "dead"
end

Class Method Details

.max_jobsObject


739
740
741
# File 'lib/sidekiq/api.rb', line 739

def self.max_jobs
  Sidekiq.options[:dead_max_jobs]
end

.timeoutObject


743
744
745
# File 'lib/sidekiq/api.rb', line 743

def self.timeout
  Sidekiq.options[:dead_timeout_in_seconds]
end

Instance Method Details

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


714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
# File 'lib/sidekiq/api.rb', line 714

def kill(message, opts = {})
  now = Time.now.to_f
  Sidekiq.redis do |conn|
    conn.multi do
      conn.zadd(name, now.to_s, message)
      conn.zremrangebyscore(name, "-inf", now - self.class.timeout)
      conn.zremrangebyrank(name, 0, - self.class.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.death_handlers.each do |handle|
      handle.call(job, r)
    end
  end
  true
end

#retry_allObject


735
736
737
# File 'lib/sidekiq/api.rb', line 735

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