Class: SidekiqUniqueJobs::LockTTL
- Inherits:
-
Object
- Object
- SidekiqUniqueJobs::LockTTL
- Includes:
- SidekiqWorkerMethods
- Defined in:
- lib/sidekiq_unique_jobs/lock_ttl.rb
Overview
Calculates timeout and expiration
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
Attributes included from SidekiqWorkerMethods
Class Method Summary collapse
-
.calculate(item) ⇒ Integer
Computes lock ttl from job arguments, sidekiq_options.
Instance Method Summary collapse
-
#calculate ⇒ Integer
Computes lock ttl from job arguments, sidekiq_options.
-
#initialize(item) ⇒ LockTTL
constructor
A new instance of LockTTL.
-
#scheduled_at ⇒ Float
The time a job is scheduled.
-
#time_until_scheduled ⇒ Integer
Calculates the time until the job is scheduled starting from now.
Methods included from SidekiqWorkerMethods
#after_unlock_hook, #default_job_options, #job_class_constantize, #job_method_defined?, #job_options, #sidekiq_job_class?
Constructor Details
Instance Attribute Details
#item ⇒ Object (readonly)
Returns the value of attribute item.
28 29 30 |
# File 'lib/sidekiq_unique_jobs/lock_ttl.rb', line 28 def item @item end |
Class Method Details
.calculate(item) ⇒ Integer
this method takes into consideration the time until a job is scheduled
Computes lock ttl from job arguments, sidekiq_options.
Falls back to {SidekiqUniqueJobs::Config#lock_ttl}
22 23 24 |
# File 'lib/sidekiq_unique_jobs/lock_ttl.rb', line 22 def self.calculate(item) new(item).calculate end |
Instance Method Details
#calculate ⇒ Integer
this method takes into consideration the time until a job is scheduled
Computes lock ttl from job arguments, sidekiq_options.
Falls back to {SidekiqUniqueJobs::Config#lock_ttl}
68 69 70 71 72 73 74 75 |
# File 'lib/sidekiq_unique_jobs/lock_ttl.rb', line 68 def calculate ttl = item[LOCK_TTL] ttl ||= [LOCK_TTL] ttl ||= item[LOCK_EXPIRATION] # TODO: Deprecate at some point ttl ||= [LOCK_EXPIRATION] # TODO: Deprecate at some point ttl ||= SidekiqUniqueJobs.config.lock_ttl ttl && (ttl.to_i + time_until_scheduled) end |
#scheduled_at ⇒ Float
The time a job is scheduled
54 55 56 |
# File 'lib/sidekiq_unique_jobs/lock_ttl.rb', line 54 def scheduled_at @scheduled_at ||= item[AT] end |
#time_until_scheduled ⇒ Integer
Calculates the time until the job is scheduled starting from now
46 47 48 49 50 |
# File 'lib/sidekiq_unique_jobs/lock_ttl.rb', line 46 def time_until_scheduled return 0 unless scheduled_at scheduled_at.to_i - Time.now.utc.to_i end |