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
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#unique_digest ⇒ Object
readonly
Returns the value of attribute unique_digest.
Attributes inherited from Strategy
Instance Method Summary collapse
-
#call { ... } ⇒ Object
Replace the old job in the queue.
-
#delete_job_by_digest ⇒ Object
Delete the job from either schedule, retry or the queue.
-
#delete_lock ⇒ Object
Delete the keys belonging to the job.
-
#initialize(item) ⇒ Replace
constructor
A new instance of Replace.
Methods inherited from Strategy
Methods included from Logging
#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger, #logging_context
Constructor Details
#initialize(item) ⇒ Replace
Returns a new instance of Replace.
12 13 14 15 16 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 12 def initialize(item) super @queue = item[QUEUE_KEY] @unique_digest = item[UNIQUE_DIGEST_KEY] end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
9 10 11 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 9 def queue @queue end |
#unique_digest ⇒ Object (readonly)
Returns the value of attribute unique_digest.
9 10 11 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 9 def unique_digest @unique_digest end |
Instance Method Details
#call { ... } ⇒ Object
Replace the old job in the queue
20 21 22 23 24 25 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 20 def call(&block) return unless delete_job_by_digest delete_lock block&.call end |
#delete_job_by_digest ⇒ Object
Delete the job from either schedule, retry or the queue
28 29 30 31 32 33 34 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 28 def delete_job_by_digest Scripts.call( :delete_job_by_digest, nil, keys: ["#{QUEUE_KEY}:#{queue}", SCHEDULE_SET, RETRY_SET], argv: [unique_digest], ) end |
#delete_lock ⇒ Object
Delete the keys belonging to the job
37 38 39 |
# File 'lib/sidekiq_unique_jobs/on_conflict/replace.rb', line 37 def delete_lock SidekiqUniqueJobs::Digests.delete_by_digest(unique_digest) end |