Skip to content

Commit

Permalink
Make sure server process stays locked (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhenrixon authored Nov 25, 2019
1 parent 29f783b commit 7116d4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ class UntilAndWhileExecuting < BaseLock
# @yield to the worker class perform method
def execute
if unlock
runtime_lock.execute { return yield }
lock_on_failure do
runtime_lock.execute { return yield }
end
else
log_warn "couldn't unlock digest: #{item[UNIQUE_DIGEST]} #{item[JID]}"
end
end

#
# Lock only when the server is processing the job
#
#
# @return [SidekiqUniqueJobs::Lock::WhileExecuting] an instance of a lock
#
private

def lock_on_failure
yield
rescue Exception # rubocop:disable Lint/RescueException
log_error("Runtime lock failed to execute job, restoring server lock")
lock
raise
end

def runtime_lock
@runtime_lock ||= SidekiqUniqueJobs::Lock::WhileExecuting.new(item, callback, redis_pool)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
.to raise_error(RuntimeError, "Hell")

expect(runtime_one.locked?).to eq(false)
expect(process_one.locked?).to eq(true)
end
end
end
Expand Down

0 comments on commit 7116d4b

Please sign in to comment.