class SidekiqUniqueJobs::LockTTL
@author Mikael Henriksson <mikael@mhenrixon.com>
Calculates timeout and expiration
def self.calculate(item)
-
(Integer)
- the number of seconds to live
Other tags:
- Note: - this method takes into consideration the time
def self.calculate(item) new(item).calculate end
def calculate
-
(Integer)
- the number of seconds to live
Other tags:
- Note: - this method takes into consideration the time
def calculate ttl = item[LOCK_TTL] ttl ||= worker_options[LOCK_TTL] ttl ||= item[LOCK_EXPIRATION] # TODO: Deprecate at some point ttl ||= worker_options[LOCK_EXPIRATION] # TODO: Deprecate at some point ttl ||= SidekiqUniqueJobs.config.lock_ttl ttl && ttl.to_i + time_until_scheduled end
def initialize(item)
(**item)
-
:at
(Float
) -- the unix time the job is scheduled at -
:class
(String
) -- the class of the sidekiq worker -
:lock_timeout
(Integer, nil
) -- the configured lock timeout -
:lock_ttl
(Integer, nil
) -- the configured lock expiration
Parameters:
-
item
(Hash
) -- the Sidekiq job hash
def initialize(item) @item = item @worker_class = item[CLASS] end
def scheduled_at
-
(Float)
- the exact unix time the job is scheduled at
def scheduled_at @scheduled_at ||= item[AT] end
def time_until_scheduled
-
(Integer)
- the number of seconds until job is scheduled
def time_until_scheduled return 0 unless scheduled_at scheduled_at.to_i - Time.now.utc.to_i end