Class: SidekiqSmartCache::Interlock
- Inherits:
-
Object
- Object
- SidekiqSmartCache::Interlock
- Defined in:
- lib/sidekiq_smart_cache/interlock.rb
Instance Attribute Summary collapse
-
#cache_tag ⇒ Object
Returns the value of attribute cache_tag.
-
#job_interlock_timeout ⇒ Object
Returns the value of attribute job_interlock_timeout.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(cache_tag, job_interlock_timeout = nil) ⇒ Interlock
constructor
A new instance of Interlock.
- #key ⇒ Object
- #lock_job? ⇒ Boolean
- #working? ⇒ Boolean
Constructor Details
#initialize(cache_tag, job_interlock_timeout = nil) ⇒ Interlock
Returns a new instance of Interlock.
6 7 8 9 |
# File 'lib/sidekiq_smart_cache/interlock.rb', line 6 def initialize(cache_tag, job_interlock_timeout=nil) @cache_tag = cache_tag @job_interlock_timeout = job_interlock_timeout end |
Instance Attribute Details
#cache_tag ⇒ Object
Returns the value of attribute cache_tag.
4 5 6 |
# File 'lib/sidekiq_smart_cache/interlock.rb', line 4 def cache_tag @cache_tag end |
#job_interlock_timeout ⇒ Object
Returns the value of attribute job_interlock_timeout.
4 5 6 |
# File 'lib/sidekiq_smart_cache/interlock.rb', line 4 def job_interlock_timeout @job_interlock_timeout end |
Instance Method Details
#clear ⇒ Object
23 24 25 |
# File 'lib/sidekiq_smart_cache/interlock.rb', line 23 def clear redis.del(key) end |
#key ⇒ Object
11 12 13 |
# File 'lib/sidekiq_smart_cache/interlock.rb', line 11 def key cache_tag + '/in-progress' end |
#lock_job? ⇒ Boolean
19 20 21 |
# File 'lib/sidekiq_smart_cache/interlock.rb', line 19 def lock_job? redis.set(key, 'winner!', nx: true) && redis.expire(key, job_interlock_timeout) end |
#working? ⇒ Boolean
15 16 17 |
# File 'lib/sidekiq_smart_cache/interlock.rb', line 15 def working? redis.get(key) end |