Sha256: 1c1aa42678342d573a37f63934021d7046c7b6d5e22067f65c7a642799a230aa
Contents?: true
Size: 1.69 KB
Versions: 10
Compression:
Stored size: 1.69 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#lock_timeout # # # @return [Integer, nil] # def default_lock_timeout SidekiqUniqueJobs.config.lock_timeout end end end
Version data entries
10 entries across 10 versions & 1 rubygems