lib/sidekiq/job_retry.rb in sidekiq-6.5.12 vs lib/sidekiq/job_retry.rb in sidekiq-7.0.0.beta1

- old
+ new

@@ -66,13 +66,13 @@ include Sidekiq::Component DEFAULT_MAX_RETRY_ATTEMPTS = 25 - def initialize(options) - @config = options - @max_retries = @config[:max_retries] || DEFAULT_MAX_RETRY_ATTEMPTS + def initialize(capsule) + @config = @capsule = capsule + @max_retries = Sidekiq.default_configuration[:max_retries] || DEFAULT_MAX_RETRY_ATTEMPTS end # The global retry handler requires only the barest of data. # We want to be able to retry as much as possible so we don't # require the job to be instantiated. @@ -89,11 +89,11 @@ msg = Sidekiq.load_json(jobstr) if msg["retry"] process_retry(nil, msg, queue, e) else - Sidekiq.death_handlers.each do |handler| + @capsule.config.death_handlers.each do |handler| handler.call(msg, e) rescue => handler_ex handle_exception(handler_ex, {context: "Error calling death handler", job: msg}) end end @@ -221,11 +221,11 @@ handle_exception(e, {context: "Error calling retries_exhausted", job: msg}) end send_to_morgue(msg) unless msg["dead"] == false - config.death_handlers.each do |handler| + @capsule.config.death_handlers.each do |handler| handler.call(msg, exception) rescue => e handle_exception(e, {context: "Error calling death handler", job: msg}) end end @@ -233,14 +233,14 @@ def send_to_morgue(msg) logger.info { "Adding dead #{msg["class"]} job #{msg["jid"]}" } payload = Sidekiq.dump_json(msg) now = Time.now.to_f - config.redis do |conn| + redis do |conn| conn.multi do |xa| xa.zadd("dead", now.to_s, payload) - xa.zremrangebyscore("dead", "-inf", now - config[:dead_timeout_in_seconds]) - xa.zremrangebyrank("dead", 0, - config[:dead_max_jobs]) + xa.zremrangebyscore("dead", "-inf", now - @capsule.config[:dead_timeout_in_seconds]) + xa.zremrangebyrank("dead", 0, - @capsule.config[:dead_max_jobs]) end end end def retry_attempts_from(msg_retry, default)