Class: Sidekiq::PowerFetch::Lock
- Inherits:
-
Object
- Object
- Sidekiq::PowerFetch::Lock
- Defined in:
- lib/sidekiq/power_fetch/lock.rb
Constant Summary collapse
- DEFAULT_INTERVAL =
2 minutes
120
- DEFAULT_RECOVER =
1 hour
3600
- KEY =
"sidekiq-power-fetch-lock"
Instance Method Summary collapse
-
#initialize(capsule) ⇒ Lock
constructor
A new instance of Lock.
- #lock ⇒ Object
Constructor Details
#initialize(capsule) ⇒ Lock
Returns a new instance of Lock.
10 11 12 13 14 15 16 17 18 |
# File 'lib/sidekiq/power_fetch/lock.rb', line 10 def initialize(capsule) @capsule = capsule @taken_at = 0 # Sidekiq processes should attempt recovery every 2 minutes. @interval = @capsule.config[:power_fetch_lock] || DEFAULT_INTERVAL # Perform recovery at most every 1 hour. @recover = @capsule.config[:power_fetch_recover] || DEFAULT_RECOVER end |
Instance Method Details
#lock ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/sidekiq/power_fetch/lock.rb', line 20 def lock return unless take? @taken_at = time # Return value is "OK" or nil. @capsule.redis do |conn| conn.set(KEY, 1, nx: true, ex: @recover) end end |