Class: SidekiqUniqueJobs::OnConflict::Reschedule

Inherits:
Strategy
  • Object
show all
Includes:
JSON, Logging, Reflectable, SidekiqWorkerMethods
Defined in:
lib/sidekiq_unique_jobs/on_conflict/reschedule.rb

Overview

Strategy to reschedule job on conflict

Author:

  • Mikael Henriksson <mikael@mhenrixon.com>

Instance Attribute Summary

Attributes included from SidekiqWorkerMethods

#job_class

Attributes inherited from Strategy

#item, #redis_pool

Instance Method Summary collapse

Methods included from Reflectable

#reflect

Methods included from JSON

dump_json, load_json, safe_load_json

Methods included from Logging

#build_message, included, #log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger, #logging_context, #with_configured_loggers_context, #with_logging_context

Methods included from SidekiqWorkerMethods

#after_unlock_hook, #default_job_options, #job_class_constantize, #job_method_defined?, #job_options, #sidekiq_job_class?

Methods inherited from Strategy

#replace?

Methods included from Timing

clock_stamp, now_f, time_source, timed

Methods included from Script::Caller

call_script, debug_lua, do_call, extract_args, max_history, normalize_argv, now_f, redis_version

Constructor Details

#initialize(item, redis_pool = nil) ⇒ Reschedule

Returns a new instance of Reschedule.

Parameters:

  • item (Hash)

    sidekiq job hash



15
16
17
18
# File 'lib/sidekiq_unique_jobs/on_conflict/reschedule.rb', line 15

def initialize(item, redis_pool = nil)
  super
  self.job_class = item[CLASS]
end

Instance Method Details

#callObject

Create a new job from the current one.

Sets the RESCHEDULED flag so the middleware skips uniqueness checks,
avoiding infinite recursion when the lock is still held.


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sidekiq_unique_jobs/on_conflict/reschedule.rb', line 23

def call
  if sidekiq_job_class?
    jid = job_class
      .set(queue: item[QUEUE].to_sym, RESCHEDULED => true)
      .perform_in(schedule_in, *item[ARGS])

    if jid
      reflect(:rescheduled, item)
    else
      reflect(:reschedule_failed, item)
    end
  else
    reflect(:unknown_sidekiq_worker, item)
  end
end

#schedule_inObject



39
40
41
# File 'lib/sidekiq_unique_jobs/on_conflict/reschedule.rb', line 39

def schedule_in
  job_class.get_sidekiq_options["schedule_in"] || 5
end