Class: SidekiqUniqueJobs::Lock::UntilExecuted
- Inherits:
-
Object
- Object
- SidekiqUniqueJobs::Lock::UntilExecuted
show all
- Extended by:
- Forwardable
- Includes:
- Unlockable
- Defined in:
- lib/sidekiq_unique_jobs/lock/until_executed.rb
Instance Method Summary
collapse
Methods included from Unlockable
after_unlock, ensure_job_id_removed, logger, unlock, unlock_by_key
Constructor Details
#initialize(item, redis_pool = nil) ⇒ UntilExecuted
Returns a new instance of UntilExecuted.
11
12
13
14
|
# File 'lib/sidekiq_unique_jobs/lock/until_executed.rb', line 11
def initialize(item, redis_pool = nil)
@item = item
@redis_pool = redis_pool
end
|
Instance Method Details
#after_yield_yield ⇒ Object
60
61
62
|
# File 'lib/sidekiq_unique_jobs/lock/until_executed.rb', line 60
def after_yield_yield
yield
end
|
#execute(callback, &blk) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/sidekiq_unique_jobs/lock/until_executed.rb', line 16
def execute(callback, &blk)
operative = true
send(:after_yield_yield, &blk)
rescue Sidekiq::Shutdown
operative = false
raise
ensure
if operative && unlock(:server)
callback.call
else
logger.fatal { "the unique_key: #{unique_key} needs to be unlocked manually" }
end
end
|
#lock(scope) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/sidekiq_unique_jobs/lock/until_executed.rb', line 38
def lock(scope)
if scope.to_sym != :client
raise ArgumentError, "#{scope} middleware can't #{__method__} #{unique_key}"
end
Scripts::AcquireLock.execute(
redis_pool,
unique_key,
item[JID_KEY],
max_lock_time
)
end
|
#max_lock_time ⇒ Object
56
57
58
|
# File 'lib/sidekiq_unique_jobs/lock/until_executed.rb', line 56
def max_lock_time
@max_lock_time ||= QueueLockTimeoutCalculator.for_item(item).seconds
end
|
#unique_key ⇒ Object
rubocop:enable MethodLength
52
53
54
|
# File 'lib/sidekiq_unique_jobs/lock/until_executed.rb', line 52
def unique_key
@unique_key ||= UniqueArgs.digest(item)
end
|
#unlock(scope) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/sidekiq_unique_jobs/lock/until_executed.rb', line 30
def unlock(scope)
unless [:server, :api, :test].include?(scope)
raise ArgumentError, "#{scope} middleware can't #{__method__} #{unique_key}"
end
unlock_by_key(unique_key, item[JID_KEY], redis_pool)
end
|