diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-10-01 13:10:30 +0900 |
---|---|---|
committer | Alessio Caiazza <acaiazza@gitlab.com> | 2018-10-02 17:08:13 +0200 |
commit | 70d015d1ba5adde82c6f38567ad51cfb85dae5f6 (patch) | |
tree | 78793de34c7ca0bb5688db8afd34f9b0a164e29e /app/workers | |
parent | a220e72c7027ecf48da73daf0d2de5315b4bc675 (diff) | |
download | gitlab-ce-70d015d1ba5adde82c6f38567ad51cfb85dae5f6.tar.gz |
Cleanup drop_stale_scheduled_builds code
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/stuck_ci_jobs_worker.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/app/workers/stuck_ci_jobs_worker.rb b/app/workers/stuck_ci_jobs_worker.rb index 821ea75703f..5028965862f 100644 --- a/app/workers/stuck_ci_jobs_worker.rb +++ b/app/workers/stuck_ci_jobs_worker.rb @@ -10,6 +10,7 @@ class StuckCiJobsWorker BUILD_PENDING_OUTDATED_TIMEOUT = 1.day BUILD_SCHEDULED_OUTDATED_TIMEOUT = 1.hour BUILD_PENDING_STUCK_TIMEOUT = 1.hour + BUILD_SCHEDULED_OUTDATED_BATCH_SIZE = 100 def perform return unless try_obtain_lease @@ -68,8 +69,12 @@ class StuckCiJobsWorker # `ci_builds` table has a partial index on `id` with `scheduled_at <> NULL` condition. # Therefore this query's first step uses Index Search, and the following expensive # filter `scheduled_at < ?` will only perform on a small subset (max: 100 rows) - Ci::Build.include(EachBatch).where('scheduled_at IS NOT NULL').each_batch(of: 100) do |relation| - relation.where('scheduled_at < ?', BUILD_SCHEDULED_OUTDATED_TIMEOUT.ago).find_each do |build| + Ci::Build.include(EachBatch) + .where('scheduled_at IS NOT NULL') + .each_batch(of: BUILD_SCHEDULED_OUTDATED_BATCH_SIZE) do |relation| + relation + .where('scheduled_at < ?', BUILD_SCHEDULED_OUTDATED_TIMEOUT.ago) + .find_each(batch_size: BUILD_SCHEDULED_OUTDATED_BATCH_SIZE) do |build| drop_build(:outdated, build, :scheduled, BUILD_SCHEDULED_OUTDATED_TIMEOUT, :schedule_expired) end end |