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

Always cancel the lease

parent ec30d98a
...@@ -9,12 +9,9 @@ class UpdateAllMirrorsWorker ...@@ -9,12 +9,9 @@ class UpdateAllMirrorsWorker
LEASE_KEY = 'update_all_mirrors'.freeze LEASE_KEY = 'update_all_mirrors'.freeze
def perform def perform
lease_uuid = try_obtain_lease with_lease do
return unless lease_uuid schedule_mirrors!
end
schedule_mirrors!
cancel_lease(lease_uuid)
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
...@@ -49,6 +46,14 @@ class UpdateAllMirrorsWorker ...@@ -49,6 +46,14 @@ class UpdateAllMirrorsWorker
private 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 def try_obtain_lease
::Gitlab::ExclusiveLease.new(LEASE_KEY, timeout: LEASE_TIMEOUT).try_obtain ::Gitlab::ExclusiveLease.new(LEASE_KEY, timeout: LEASE_TIMEOUT).try_obtain
end 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