Commit a26e25ea authored by Kamil Trzcinski's avatar Kamil Trzcinski

Optimise StuckCiJobsWorker

parent 03b891c5
......@@ -45,11 +45,15 @@ class StuckCiJobsWorker
end
def search(status, timeout)
builds = Ci::Build.where(status: status).where('ci_builds.updated_at < ?', timeout.ago)
builds.joins(:project).merge(Project.without_deleted).includes(:tags, :runner, project: :namespace).find_each(batch_size: 50).each do |build|
Ci::Build.where(status: status).in_batches(of: 1000) do |batch|
batch = batch.where('ci_builds.updated_at < ?', timeout.ago)
.joins(:project).merge(Project.without_deleted)
.includes(:tags, :runner, project: :namespace)
batch.each do |build|
yield(build)
end
end
end
def drop_build(type, build, status, timeout)
Rails.logger.info "#{self.class}: Dropping #{type} build #{build.id} for runner #{build.runner_id} (status: #{status}, timeout: #{timeout})"
......@@ -58,3 +62,4 @@ class StuckCiJobsWorker
end
end
end
---
title: Optimise StuckCiJobsWorker using cheap SQL query outside, and expensive inside
merge_request:
author:
type: performance
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