summaryrefslogtreecommitdiff
path: root/app/workers
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2017-02-07 14:00:46 +0100
committerTomasz Maczukin <tomasz@maczukin.pl>2017-03-01 13:29:52 +0100
commit8d1cdc940142590eab34d190def2ac3bcd51167f (patch)
tree84caab45953d3af403c07cc9a1bb477d7822c035 /app/workers
parente5bafed83714d2e96476446b9b2ebdebe3dffe35 (diff)
downloadgitlab-ce-8d1cdc940142590eab34d190def2ac3bcd51167f.tar.gz
Update stuck and outdated builds cleanup worker
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/stuck_ci_builds_worker.rb38
1 files changed, 31 insertions, 7 deletions
diff --git a/app/workers/stuck_ci_builds_worker.rb b/app/workers/stuck_ci_builds_worker.rb
index b70df5a1afa..b9dac807b23 100644
--- a/app/workers/stuck_ci_builds_worker.rb
+++ b/app/workers/stuck_ci_builds_worker.rb
@@ -2,18 +2,42 @@ class StuckCiBuildsWorker
include Sidekiq::Worker
include CronjobQueue
- BUILD_STUCK_TIMEOUT = 1.day
+ BUILD_RUNNING_OUTDATED_TIMEOUT = 1.hour
+ BUILD_PENDING_OUTDATED_TIMEOUT = 1.day
+ BUILD_PENDING_STUCK_TIMEOUT = 1.hour
def perform
Rails.logger.info 'Cleaning stuck builds'
- builds = Ci::Build.joins(:project).running_or_pending.where('ci_builds.updated_at < ?', BUILD_STUCK_TIMEOUT.ago)
- builds.find_each(batch_size: 50).each do |build|
- Rails.logger.debug "Dropping stuck #{build.status} build #{build.id} for runner #{build.runner_id}"
- build.drop
+ drop :running, BUILD_RUNNING_OUTDATED_TIMEOUT
+ drop :pending, BUILD_PENDING_OUTDATED_TIMEOUT
+ drop_stuck :pending, BUILD_PENDING_STUCK_TIMEOUT
+ end
+
+ private
+
+ def drop(status, timeout)
+ search(status, timeout) do |build|
+ drop_build :outdated, build, status, timeout
+ end
+ end
+
+ def drop_stuck(status, timeout)
+ search(status, timeout) do |build|
+ return unless build.stuck?
+ drop_build :stuck, build, status, timeout
end
+ end
+
+ def search(status, timeout)
+ builds = Ci::Build.where(status: status).where('ci_builds.updated_at < ?', timeout.ago)
+ builds.joins(:project).find_each(batch_size: 50).each do |build|
+ yield(build)
+ end
+ end
- # Update builds that failed to drop
- builds.update_all(status: 'failed')
+ 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})"
+ build.drop
end
end