summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-02-28 01:24:23 +0900
committerShinya Maeda <shinya@gitlab.com>2018-03-06 21:43:19 +0900
commitc645d40a56a8291e61a597e956bb2a3659fe123a (patch)
tree43085aca8f359327fdae85f536180109b7cd3d5f
parentcd3931876590448108ba54fa89274941ff8a97fe (diff)
downloadgitlab-ce-c645d40a56a8291e61a597e956bb2a3659fe123a.tar.gz
Use find_in_batches for rake task
-rw-r--r--lib/tasks/gitlab/traces.rake14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/tasks/gitlab/traces.rake b/lib/tasks/gitlab/traces.rake
index f45edc922aa..04b939d23c9 100644
--- a/lib/tasks/gitlab/traces.rake
+++ b/lib/tasks/gitlab/traces.rake
@@ -8,10 +8,18 @@ namespace :gitlab do
logger = Logger.new(STDOUT)
logger.info('Archiving legacy traces')
- job_ids = Ci::Build.complete.without_trace_artifact.pluck(:id)
- job_ids = job_ids.map { |build_id| [build_id] }
+ Ci::Build.joins('RIGHT JOIN ci_job_artifacts ON ci_job_artifacts.job_id = ci_builds.id')
+ .finished
+ .where('ci_job_artifacts.file_type <> 3')
+ .group('ci_builds.id')
+ .order(id: :asc)
+ .find_in_batches(batch_size: 1000) do |jobs|
+ job_ids = jobs.map { |job| [job.id] }
- ArchiveLegacyTraceWorker.bulk_perform_async(job_ids)
+ ArchiveLegacyTraceWorker.bulk_perform_async(job_ids)
+
+ logger.info("Scheduled #{job_ids.count} jobs. From #{job_ids.min} #{job_ids.max}")
+ end
end
end
end