/
until_and_while_executing.rb
30 lines (27 loc) · 1.02 KB
/
until_and_while_executing.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true
module SidekiqUniqueJobs
class Lock
# Locks jobs while the job is executing in the server process
# - Locks on perform_in or perform_async (see {UntilExecuting})
# - Unlocks before yielding to the worker's perform method (see {UntilExecuting})
# - Locks before yielding to the worker's perform method (see {WhileExecuting})
# - Unlocks after yielding to the worker's perform method (see {WhileExecuting})
#
# See {#lock} for more information about the client.
# See {#execute} for more information about the server
#
# @author Mikael Henriksson <mikael@zoolutions.se>
class UntilAndWhileExecuting < BaseLock
# Executes in the Sidekiq server process
# @yield to the worker class perform method
def execute
return unless locked?
unlock
runtime_lock.execute { yield }
end
def runtime_lock
@runtime_lock ||= SidekiqUniqueJobs::Lock::WhileExecuting.new(item, callback, redis_pool)
end
end
end
end