Sha256: 935d02cc18b1ee9b374d1eddbfba6ca1a2d46064d507b4b03ee3115d91bfcd5f

Contents?: true

Size: 1.71 KB

Versions: 6

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  # Calculates timeout and expiration
  #
  # @author Mikael Henriksson <mikael@zoolutions.se>
  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
      @worker_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_worker_options[LOCK_TIMEOUT]
      timeout = default_lock_timeout if default_lock_timeout
      timeout = worker_options[LOCK_TIMEOUT] if worker_options.key?(LOCK_TIMEOUT)
      timeout
    end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.0.beta15 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.0.0.beta14 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.0.0.beta13 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.0.0.beta12 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.0.0.beta11 lib/sidekiq_unique_jobs/lock_timeout.rb
sidekiq-unique-jobs-7.0.0.beta10 lib/sidekiq_unique_jobs/lock_timeout.rb