Commit d58bab4a authored by Kamil Trzcinski's avatar Kamil Trzcinski

Use not-ordered search

parent a26e25ea
...@@ -45,12 +45,17 @@ class StuckCiJobsWorker ...@@ -45,12 +45,17 @@ class StuckCiJobsWorker
end end
def search(status, timeout) def search(status, timeout)
Ci::Build.where(status: status).in_batches(of: 1000) do |batch| loop do
batch = batch.where('ci_builds.updated_at < ?', timeout.ago) jobs = Ci::Build.where(status: status)
.where('ci_builds.updated_at < ?', timeout.ago)
.joins(:project).merge(Project.without_deleted) .joins(:project).merge(Project.without_deleted)
.includes(:tags, :runner, project: :namespace) .includes(:tags, :runner, project: :namespace)
batch.each do |build| .limit(100)
yield(build) .to_a
break if jobs.empty?
jobs.each do |job|
yield(job)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment