Sha256: 425b37f541578e5b422d0f9d4771334ec71c364439a63882cb64286e248e5649

Contents?: true

Size: 1.68 KB

Versions: 24

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  # Calculates timeout and expiration
  #
  # @author Mikael Henriksson <mikael@mhenrixon.com>
  class LockTimeout
    # includes "SidekiqUniqueJobs::SidekiqWorkerMethods"
    # @!parse include SidekiqUniqueJobs::SidekiqWorkerMethods
    include SidekiqUniqueJobs::SidekiqWorkerMethods

    #
    # Calculates the timeout for a Sidekiq job
    #
    # @param [Hash] item sidekiq job hash
    #
    # @return [Integer] timeout in seconds
    #
    def self.calculate(item)
      new(item).calculate
    end

    # @!attribute [r] item
    #   @return [Hash] the Sidekiq job hash
    attr_reader :item

    # @param [Hash] item the Sidekiq job hash
    # @option item [Integer, nil] :lock_ttl the configured lock expiration
    # @option item [Integer, nil] :lock_timeout the configured lock timeout
    # @option item [String] :class the class of the sidekiq worker
    # @option item [Float] :at the unix time the job is scheduled at
    def initialize(item)
      @item = item
      self.job_class = item[CLASS]
    end

    #
    # Finds a lock timeout in either of
    #  default worker options, {default_lock_timeout} or provided worker_options
    #
    #
    # @return [Integer, nil]
    #
    def calculate
      timeout = default_job_options[LOCK_TIMEOUT]
      timeout = default_lock_timeout if default_lock_timeout
      timeout = job_options[LOCK_TIMEOUT] if job_options.key?(LOCK_TIMEOUT)
      timeout
    end

    #
    # The configured default_lock_timeout
    # @see SidekiqUniqueJobs::Config#lock_timeout
    #
    #
    # @return [Integer, nil]
    #
    def default_lock_timeout
      SidekiqUniqueJobs.config.lock_timeout
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-8.0.10 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.1.33 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.1.32 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-8.0.9 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-8.0.8 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-8.0.7 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-8.0.6 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.1.31 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-8.0.5 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-8.0.4 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.1.30 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-8.0.3 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-8.0.2 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-8.0.1 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-8.0.0 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.1.29 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.1.28 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.1.27 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.1.26 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.1.25 lib/sidekiq_unique_jobs/lock_timeout.rb