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