diff options
Diffstat (limited to 'app/workers/stuck_ci_jobs_worker.rb')
-rw-r--r-- | app/workers/stuck_ci_jobs_worker.rb | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/app/workers/stuck_ci_jobs_worker.rb b/app/workers/stuck_ci_jobs_worker.rb index 6282c9200b1..72fcf06dce1 100644 --- a/app/workers/stuck_ci_jobs_worker.rb +++ b/app/workers/stuck_ci_jobs_worker.rb @@ -2,6 +2,7 @@ class StuckCiJobsWorker # rubocop:disable Scalability/IdempotentWorker include ApplicationWorker + include ExclusiveLeaseGuard # rubocop:disable Scalability/CronWorkerContext # This is an instance-wide cleanup query, so there's no meaningful @@ -14,28 +15,18 @@ class StuckCiJobsWorker # rubocop:disable Scalability/IdempotentWorker feature_category :continuous_integration worker_resource_boundary :cpu - EXCLUSIVE_LEASE_KEY = 'stuck_ci_builds_worker_lease' - def perform Ci::StuckBuilds::DropRunningWorker.perform_in(20.minutes) Ci::StuckBuilds::DropScheduledWorker.perform_in(40.minutes) - return unless try_obtain_lease - - begin + try_obtain_lease do Ci::StuckBuilds::DropService.new.execute - ensure - remove_lease end end private - def try_obtain_lease - @uuid = Gitlab::ExclusiveLease.new(EXCLUSIVE_LEASE_KEY, timeout: 30.minutes).try_obtain - end - - def remove_lease - Gitlab::ExclusiveLease.cancel(EXCLUSIVE_LEASE_KEY, @uuid) + def lease_timeout + 30.minutes end end |