traces.rake 710 字节
Newer Older
1 2 3 4 5 6 7 8 9 10
require 'logger'
require 'resolv-replace'

desc "GitLab | Archive legacy traces to trace artifacts"
namespace :gitlab do
  namespace :traces do
    task archive: :environment do
      logger = Logger.new(STDOUT)
      logger.info('Archiving legacy traces')

S
Shinya Maeda 已提交
11 12 13
      Ci::Build.finished
        .where('NOT EXISTS (?)',
          Ci::JobArtifact.select(1).trace.where('ci_builds.id = ci_job_artifacts.job_id'))
S
Shinya Maeda 已提交
14 15 16
        .order(id: :asc)
        .find_in_batches(batch_size: 1000) do |jobs|
        job_ids = jobs.map { |job| [job.id] }
17

18
        ArchiveTraceWorker.bulk_perform_async(job_ids)
S
Shinya Maeda 已提交
19

S
Shinya Maeda 已提交
20
        logger.info("Scheduled #{job_ids.count} jobs. From #{job_ids.min} to #{job_ids.max}")
S
Shinya Maeda 已提交
21
      end
22 23 24
    end
  end
end