diff options
author | Tomasz Maczukin <tomasz@maczukin.pl> | 2017-02-08 01:06:16 +0300 |
---|---|---|
committer | Tomasz Maczukin <tomasz@maczukin.pl> | 2017-03-01 15:29:52 +0300 |
commit | 0ba385b363879f270c767aab6c1799a8e675a263 (patch) | |
tree | 002964ed32cb8c247682505a227e7d26a11a8283 /app/workers | |
parent | a4e996d77315a9d2598e32fab42436b1a04fadcb (diff) |
Add exclusive lease for stuck_ci_builds_worker
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/stuck_ci_builds_worker.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/app/workers/stuck_ci_builds_worker.rb b/app/workers/stuck_ci_builds_worker.rb index b9dac807b23..4eba311d063 100644 --- a/app/workers/stuck_ci_builds_worker.rb +++ b/app/workers/stuck_ci_builds_worker.rb @@ -7,7 +7,9 @@ class StuckCiBuildsWorker BUILD_PENDING_STUCK_TIMEOUT = 1.hour def perform - Rails.logger.info 'Cleaning stuck builds' + return unless try_obtain_lease + + Rails.logger.info "#{self.class}: Cleaning stuck builds" drop :running, BUILD_RUNNING_OUTDATED_TIMEOUT drop :pending, BUILD_PENDING_OUTDATED_TIMEOUT @@ -16,6 +18,13 @@ class StuckCiBuildsWorker private + def try_obtain_lease + Gitlab::ExclusiveLease.new( + 'stuck_ci_builds_worker_lease', + timeout: 30.minutes + ).try_obtain + end + def drop(status, timeout) search(status, timeout) do |build| drop_build :outdated, build, status, timeout @@ -37,7 +46,7 @@ class StuckCiBuildsWorker end def drop_build(type, build, status, timeout) - Rails.logger.info "#{self.class}: Dropping #{type.to_s} build #{build.id} for runner #{build.runner_id} (status: #{status}, timeout: #{timeout})" + Rails.logger.info "#{self.class}: Dropping #{type} build #{build.id} for runner #{build.runner_id} (status: #{status}, timeout: #{timeout})" build.drop end end |