Use find_in_batches for rake task
This commit is contained in:
		
							parent
							
								
									cd39318765
								
							
						
					
					
						commit
						c645d40a56
					
				|  | @ -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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue