Class: SidekiqSmartCache::Interlock

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_smart_cache/interlock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_tagObject

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_timeoutObject

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

#clearObject



23
24
25
# File 'lib/sidekiq_smart_cache/interlock.rb', line 23

def clear
  redis.del(key)
end

#keyObject



11
12
13
# File 'lib/sidekiq_smart_cache/interlock.rb', line 11

def key
  cache_tag + '/in-progress'
end

#lock_job?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


15
16
17
# File 'lib/sidekiq_smart_cache/interlock.rb', line 15

def working?
  redis.get(key)
end