Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2017-02-09 05:29:38 +0300
committerTomasz Maczukin <tomasz@maczukin.pl>2017-03-01 15:29:52 +0300
commit6db7c232f402b677e9a613161e419141017232b9 (patch)
tree0e8d886bab248d0195ec1d47d25d9f756bcede44 /app/workers
parent48cb391cf7f11bae785fb89208fb5cf0303e326f (diff)
Add minor updates
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/stuck_ci_builds_worker.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/app/workers/stuck_ci_builds_worker.rb b/app/workers/stuck_ci_builds_worker.rb
index 1c1e71cca23..e9bd3f180b7 100644
--- a/app/workers/stuck_ci_builds_worker.rb
+++ b/app/workers/stuck_ci_builds_worker.rb
@@ -2,6 +2,8 @@ class StuckCiBuildsWorker
include Sidekiq::Worker
include CronjobQueue
+ EXCLUSIVE_LEASE_KEY = 'stuck_ci_builds_worker_lease'
+
BUILD_RUNNING_OUTDATED_TIMEOUT = 1.hour
BUILD_PENDING_OUTDATED_TIMEOUT = 1.day
BUILD_PENDING_STUCK_TIMEOUT = 1.hour
@@ -11,20 +13,26 @@ class StuckCiBuildsWorker
Rails.logger.info "#{self.class}: Cleaning stuck builds"
- drop :running, BUILD_RUNNING_OUTDATED_TIMEOUT
- drop :pending, BUILD_PENDING_OUTDATED_TIMEOUT
+ drop :running, BUILD_RUNNING_OUTDATED_TIMEOUT
+ drop :pending, BUILD_PENDING_OUTDATED_TIMEOUT
drop_stuck :pending, BUILD_PENDING_STUCK_TIMEOUT
+
+ remove_lease
end
private
def try_obtain_lease
- Gitlab::ExclusiveLease.new(
- 'stuck_ci_builds_worker_lease',
- timeout: 30.minutes
+ @uuid = Gitlab::ExclusiveLease.new(
+ EXCLUSIVE_LEASE_KEY,
+ timeout: 30.minutes
).try_obtain
end
+ def remove_lease
+ Gitlab::ExclusiveLease.cancel(EXCLUSIVE_LEASE_KEY, @uuid)
+ end
+
def drop(status, timeout)
search(status, timeout) do |build|
drop_build :outdated, build, status, timeout