Commit 06629cc6 authored by Andreas Brandl's avatar Andreas Brandl

Always cancel the lease

parent ec30d98a
......@@ -9,12 +9,9 @@ class UpdateAllMirrorsWorker
LEASE_KEY = 'update_all_mirrors'.freeze
def perform
lease_uuid = try_obtain_lease
return unless lease_uuid
schedule_mirrors!
cancel_lease(lease_uuid)
with_lease do
schedule_mirrors!
end
end
# rubocop: disable CodeReuse/ActiveRecord
......@@ -49,6 +46,14 @@ class UpdateAllMirrorsWorker
private
def with_lease
if lease_uuid = try_obtain_lease
yield
end
ensure
cancel_lease(lease_uuid) if lease_uuid
end
def try_obtain_lease
::Gitlab::ExclusiveLease.new(LEASE_KEY, timeout: LEASE_TIMEOUT).try_obtain
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment