Sha256: dd3b636bbb7c15b17a5af8744855873cf752c5676e2e163b606e4bb37fb483cf

Contents?: true

Size: 1.25 KB

Versions: 14

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  # Utility module to help manage unique keys in redis.
  # Useful for deleting keys that for whatever reason wasn't deleted
  #
  # @author Mikael Henriksson <mikael@zoolutions.se>
  module Unlockable
    module_function

    # Unlocks a job.
    # @param [Hash] item a Sidekiq job hash
    def unlock(item)
      SidekiqUniqueJobs::Job.add_digest(item)
      SidekiqUniqueJobs::Locksmith.new(item).unlock
    end

    # Unlocks a job.
    # @param [Hash] item a Sidekiq job hash
    def unlock!(item)
      SidekiqUniqueJobs::Job.add_digest(item)
      SidekiqUniqueJobs::Locksmith.new(item).unlock!
    end

    # Deletes a lock unless it has ttl
    #
    # This is good for situations when a job is locked by another item
    # @param [Hash] item a Sidekiq job hash
    def delete(item)
      SidekiqUniqueJobs::Job.add_digest(item)
      SidekiqUniqueJobs::Locksmith.new(item).delete
    end

    # Deletes a lock regardless of if it was locked or has ttl.
    #
    # This is good for situations when a job is locked by another item
    # @param [Hash] item a Sidekiq job hash
    def delete!(item)
      SidekiqUniqueJobs::Job.add_digest(item)
      SidekiqUniqueJobs::Locksmith.new(item).delete!
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.0.beta25 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta24 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta23 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta22 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta21 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta20 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta19 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta18 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta17 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta16 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta15 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta14 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta13 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta12 lib/sidekiq_unique_jobs/unlockable.rb