Sha256: ae25910e05924987f77a273e440dee679db4ec9d839c3ddb446bd6e665a0c496

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 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::UniqueArgs.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::UniqueArgs.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::UniqueArgs.digest(item)
      SidekiqUniqueJobs::Locksmith.new(item).delete!
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.0.beta9 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta8 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta7 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta6 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta5 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta4 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta3 lib/sidekiq_unique_jobs/unlockable.rb
sidekiq-unique-jobs-7.0.0.beta2 lib/sidekiq_unique_jobs/unlockable.rb