Class: SidekiqUniqueJobs::LockTimeout

Inherits:
Object
  • Object
show all
Includes:
SidekiqWorkerMethods
Defined in:
lib/sidekiq_unique_jobs/lock_timeout.rb

Overview

Calculates timeout and expiration

Author:

Instance Attribute Summary collapse

Attributes included from SidekiqWorkerMethods

#job_class

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SidekiqWorkerMethods

#after_unlock_hook, #default_job_options, #job_class_constantize, #job_method_defined?, #job_options, #sidekiq_job_class?

Constructor Details

#initialize(item) ⇒ LockTimeout

Returns a new instance of LockTimeout.

Parameters:

  • item (Hash)

    the Sidekiq job hash

Options Hash (item):

  • :lock_ttl (Integer, nil)

    the configured lock expiration

  • :lock_timeout (Integer, nil)

    the configured lock timeout

  • :class (String)

    the class of the sidekiq worker

  • :at (Float)

    the unix time the job is scheduled at



32
33
34
35
# File 'lib/sidekiq_unique_jobs/lock_timeout.rb', line 32

def initialize(item)
  @item = item
  self.job_class = item[CLASS]
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



25
26
27
# File 'lib/sidekiq_unique_jobs/lock_timeout.rb', line 25

def item
  @item
end

Class Method Details

.calculate(item) ⇒ Integer

Calculates the timeout for a Sidekiq job

Parameters:

  • item (Hash)

    sidekiq job hash

Returns:

  • (Integer)

    timeout in seconds



19
20
21
# File 'lib/sidekiq_unique_jobs/lock_timeout.rb', line 19

def self.calculate(item)
  new(item).calculate
end

Instance Method Details

#calculateInteger?

Finds a lock timeout in either of

default worker options, {default_lock_timeout} or provided worker_options

Returns:

  • (Integer, nil)


44
45
46
47
48
49
# File 'lib/sidekiq_unique_jobs/lock_timeout.rb', line 44

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

#default_lock_timeoutInteger?

The configured default_lock_timeout

Returns:

  • (Integer, nil)

See Also:

  • Config#lock_timeout


58
59
60
# File 'lib/sidekiq_unique_jobs/lock_timeout.rb', line 58

def default_lock_timeout
  SidekiqUniqueJobs.config.lock_timeout
end