Sha256: b24cd1882121300f7edb7c1f57418728639023e6ae4f032e7fac06b9caf2f007

Contents?: true

Size: 1.43 KB

Versions: 47

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  # Utility class to append uniqueness to the sidekiq job hash
  #
  # @author Mikael Henriksson <mikael@mhenrixon.com>
  module Job
    extend self

    # Adds timeout, expiration, lock_args, lock_prefix and lock_digest to the sidekiq job hash
    # @return [Hash] the job hash
    def prepare(item)
      stringify_on_conflict_hash(item)
      add_lock_timeout(item)
      add_lock_ttl(item)
      add_digest(item)
    end

    # Adds lock_args, lock_prefix and lock_digest to the sidekiq job hash
    # @return [Hash] the job hash
    def add_digest(item)
      add_lock_prefix(item)
      add_lock_args(item)
      add_lock_digest(item)

      item
    end

    private

    def stringify_on_conflict_hash(item)
      on_conflict = item[ON_CONFLICT]
      return unless on_conflict.is_a?(Hash)

      item[ON_CONFLICT] = on_conflict.deep_stringify_keys
    end

    def add_lock_ttl(item)
      item[LOCK_TTL] = SidekiqUniqueJobs::LockTTL.calculate(item)
    end

    def add_lock_timeout(item)
      item[LOCK_TIMEOUT] ||= SidekiqUniqueJobs::LockTimeout.calculate(item)
    end

    def add_lock_args(item)
      item[LOCK_ARGS] ||= SidekiqUniqueJobs::LockArgs.call(item)
    end

    def add_lock_digest(item)
      item[LOCK_DIGEST] ||= SidekiqUniqueJobs::LockDigest.call(item)
    end

    def add_lock_prefix(item)
      item[LOCK_PREFIX] ||= SidekiqUniqueJobs.config.lock_prefix
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-8.0.2 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-8.0.1 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-8.0.0 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.29 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.28 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.27 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.26 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.25 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.24 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.23 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.22 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.21 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.20 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.19 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.18 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.17 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.16 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.15 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.14 lib/sidekiq_unique_jobs/job.rb
sidekiq-unique-jobs-7.1.13 lib/sidekiq_unique_jobs/job.rb