Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle failure in starting subscribers more gracefully #280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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