class SidekiqUniqueJobs::OnConflict::Replace
Strategy
to replace the job on conflict
@author Mikael Henriksson <mikael@mhenrixon.com>
Attributes
@!attribute [r] lock_digest
@return [String] the unique digest to use for locking
@!attribute [r] queue
@return [String] rthe sidekiq queue this job belongs to
Public Class Methods
Source
# File lib/sidekiq_unique_jobs/on_conflict/replace.rb, line 23 def initialize(item, redis_pool = nil) super @queue = item[QUEUE] @lock_digest = item[LOCK_DIGEST] end
Initialize a new Replace
strategy
@param [Hash] item sidekiq job hash
Calls superclass method
SidekiqUniqueJobs::OnConflict::Strategy::new
Public Instance Methods
Source
# 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
Replace
the old job in the queue
@return [void] <description>
@yield to retry the lock after deleting the old one
Source
# 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 the job from either schedule, retry or the queue
@return [String] the deleted job hash @return [nil] when deleting nothing
Source
# File lib/sidekiq_unique_jobs/on_conflict/replace.rb, line 67 def delete_lock digests.delete_by_digest(lock_digest, runtime: false) end
Delete the keys belonging to the job
@return [Integer] the number of keys deleted
Source
# File lib/sidekiq_unique_jobs/on_conflict/replace.rb, line 77 def digests @digests ||= SidekiqUniqueJobs::Digests.new end
Access to the {Digests}
@return [Digests] and instance with digests