Class: SidekiqUniqueJobs::OnConflict::Replace
- Defined in:
- lib/sidekiq_unique_jobs/on_conflict/replace.rb
Overview
Strategy to replace the job on conflict
Instance Attribute Summary collapse
-
#lock_digest ⇒ Object
readonly
Returns the value of attribute lock_digest.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Attributes inherited from Strategy
Instance Method Summary collapse
-
#call { ... } ⇒ void
Replace the old job in the queue.
-
#delete_job_by_digest ⇒ String?
Delete the job from either schedule, retry or the queue.
-
#delete_lock ⇒ Integer
Delete the keys belonging to the job.
-
#digests ⇒ Digests
Access to the Digests.
-
#initialize(item, redis_pool = nil) ⇒ Replace
constructor
Initialize a new Replace strategy.
Methods inherited from Strategy
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
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 JSON
dump_json, load_json, safe_load_json
Constructor Details
#initialize(item, redis_pool = nil) ⇒ Replace
Initialize a new Replace strategy
23 24 25 26 27 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 23 def initialize(item, redis_pool = nil) super(item, redis_pool) @queue = item[QUEUE] @lock_digest = item[LOCK_DIGEST] end |
Instance Attribute Details
#lock_digest ⇒ Object (readonly)
Returns the value of attribute lock_digest.
16 17 18 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 16 def lock_digest @lock_digest end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
12 13 14 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 12 def queue @queue end |
Instance Method Details
#call { ... } ⇒ void
This method returns an undefined value.
Replace the old job in the queue
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 37 def call(&block) return unless (deleted_job = delete_job_by_digest) log_info("Deleted job: #{deleted_job}") if (del_count = delete_lock) log_info("Deleted `#{del_count}` keys for #{lock_digest}") end block&.call end |
#delete_job_by_digest ⇒ String?
Delete the job from either schedule, retry or the queue
55 56 57 58 59 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 55 def delete_job_by_digest call_script(:delete_job_by_digest, keys: ["#{QUEUE}:#{queue}", SCHEDULE, RETRY], argv: [lock_digest]) end |
#delete_lock ⇒ Integer
Delete the keys belonging to the job
67 68 69 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 67 def delete_lock digests.delete_by_digest(lock_digest, runtime: false) end |
#digests ⇒ Digests
Access to the Digests
77 78 79 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 77 def digests @digests ||= SidekiqUniqueJobs::Digests.new end |