Class: SidekiqUniqueJobs::Scripts::ReleaseLock

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sidekiq_unique_jobs/scripts/release_lock.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis_pool, unique_key, jid) ⇒ ReleaseLock

Returns a new instance of ReleaseLock.

Raises:


15
16
17
18
19
20
21
22
# File 'lib/sidekiq_unique_jobs/scripts/release_lock.rb', line 15

def initialize(redis_pool, unique_key, jid)
  raise UniqueKeyMissing, 'unique_key is required' if unique_key.nil?
  raise JidMissing, 'jid is required' if jid.nil?

  @redis_pool    = redis_pool
  @unique_key    = unique_key
  @jid           = jid
end

Instance Attribute Details

#jidObject (readonly)

Returns the value of attribute jid


13
14
15
# File 'lib/sidekiq_unique_jobs/scripts/release_lock.rb', line 13

def jid
  @jid
end

#redis_poolObject (readonly)

Returns the value of attribute redis_pool


13
14
15
# File 'lib/sidekiq_unique_jobs/scripts/release_lock.rb', line 13

def redis_pool
  @redis_pool
end

#unique_keyObject (readonly)

Returns the value of attribute unique_key


13
14
15
# File 'lib/sidekiq_unique_jobs/scripts/release_lock.rb', line 13

def unique_key
  @unique_key
end

Class Method Details

.execute(redis_pool, unique_key, jid) ⇒ Object


9
10
11
# File 'lib/sidekiq_unique_jobs/scripts/release_lock.rb', line 9

def self.execute(redis_pool, unique_key, jid)
  new(redis_pool, unique_key, jid).execute
end

Instance Method Details

#executeObject


24
25
26
27
28
29
30
# File 'lib/sidekiq_unique_jobs/scripts/release_lock.rb', line 24

def execute
  result = Scripts.call(:release_lock, redis_pool,
                        keys: [unique_key],
                        argv: [jid])

  handle_result(result)
end

#handle_result(result) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sidekiq_unique_jobs/scripts/release_lock.rb', line 32

def handle_result(result)
  case result
  when 1
    logger.debug { "successfully unlocked #{unique_key}" }
    true
  when 0
    logger.debug { "expiring lock #{unique_key} is not owned by #{jid}" }
    false
  when -1
    logger.debug { "#{unique_key} is not a known key" }
    false
  else
    raise UnexpectedValue, "failed to release lock : unexpected return value (#{result})"
  end
end