Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions lib/qless/worker/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,24 @@ def on_current_job_lock_lost(&block)
end

def listen_for_lost_lock
subscribers = uniq_clients.map do |client|
Subscriber.start(client, "ql:w:#{client.worker_name}", log: @log) do |_, message|
if message['event'] == 'lock_lost'
with_current_job do |job|
if job && message['jid'] == job.jid
@on_current_job_lock_lost.call(job)
subscribers = []
begin
uniq_clients.each do |client|
subscribers << Subscriber.start(client, "ql:w:#{client.worker_name}", log: @log) do |_, message|
if message['event'] == 'lock_lost'
with_current_job do |job|
if job && message['jid'] == job.jid
@on_current_job_lock_lost.call(job)
end
end
end
end
end
end

yield
ensure
subscribers.each(&:stop)
yield
ensure
subscribers.each(&:stop)
end
end

private
Expand Down