diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-11-21 21:49:10 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-11-27 13:56:15 +0300 |
commit | d58bab4aa535a6a82416b9bf664e99468ad18e4b (patch) | |
tree | e543bf91b76115e8f334790cf12617d5441a27c6 /app/workers/stuck_ci_jobs_worker.rb | |
parent | a26e25ea757f475afa1b6fd667c58fe15e306022 (diff) |
Use not-ordered search
Diffstat (limited to 'app/workers/stuck_ci_jobs_worker.rb')
-rw-r--r-- | app/workers/stuck_ci_jobs_worker.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/app/workers/stuck_ci_jobs_worker.rb b/app/workers/stuck_ci_jobs_worker.rb index 566b4507965..365a77c5be4 100644 --- a/app/workers/stuck_ci_jobs_worker.rb +++ b/app/workers/stuck_ci_jobs_worker.rb @@ -45,12 +45,17 @@ class StuckCiJobsWorker end def search(status, timeout) - Ci::Build.where(status: status).in_batches(of: 1000) do |batch| - batch = batch.where('ci_builds.updated_at < ?', timeout.ago) + loop do + jobs = Ci::Build.where(status: status) + .where('ci_builds.updated_at < ?', timeout.ago) .joins(:project).merge(Project.without_deleted) .includes(:tags, :runner, project: :namespace) - batch.each do |build| - yield(build) + .limit(100) + .to_a + break if jobs.empty? + + jobs.each do |job| + yield(job) end end end |