Add rake task. Adopt the latest fix. Drop CreateTraceArtifactService
This commit is contained in:
parent
f0d7a2ffc4
commit
32c1501d69
|
@ -1,36 +0,0 @@
|
|||
module Ci
|
||||
class CreateTraceArtifactService < BaseService
|
||||
def execute(job)
|
||||
return if job.job_artifacts_trace
|
||||
|
||||
job.trace.read do |stream|
|
||||
break unless stream.file?
|
||||
|
||||
clone_file!(stream.path, JobArtifactUploader.workhorse_upload_path) do |clone_path|
|
||||
create_job_trace!(job, clone_path)
|
||||
FileUtils.rm(stream.path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_job_trace!(job, path)
|
||||
File.open(path) do |stream|
|
||||
job.create_job_artifacts_trace!(
|
||||
project: job.project,
|
||||
file_type: :trace,
|
||||
file: stream)
|
||||
end
|
||||
end
|
||||
|
||||
def clone_file!(src_path, temp_dir)
|
||||
FileUtils.mkdir_p(temp_dir)
|
||||
Dir.mktmpdir('tmp-trace', temp_dir) do |dir_path|
|
||||
temp_path = File.join(dir_path, "job.log")
|
||||
FileUtils.copy(src_path, temp_path)
|
||||
yield(temp_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
class ArchiveLegacyTraceWorker
|
||||
include ApplicationWorker
|
||||
include ObjectStorageQueue
|
||||
|
||||
def perform(job_id)
|
||||
Ci::Build.find_by(id: job_id).try do |job|
|
||||
job.trace.archive!
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,10 +2,8 @@ class CreateTraceArtifactWorker
|
|||
include ApplicationWorker
|
||||
include PipelineQueue
|
||||
|
||||
# TODO: this worker should use BackgroundMigration or ObjectStorage queue
|
||||
|
||||
def perform(job_id)
|
||||
Ci::Build.preload(:project, :user).find_by(id: job_id).try do |job|
|
||||
Ci::Build.find_by(id: job_id).try do |job|
|
||||
job.trace.archive!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -112,18 +112,28 @@ module Gitlab
|
|||
private
|
||||
|
||||
def archive_stream!(stream)
|
||||
file = Tempfile.new('trace.log')
|
||||
size = IO.copy_stream(file, stream)
|
||||
raise 'Not all saved' unless size == stream.size
|
||||
file.close
|
||||
clone_file!(stream, JobArtifactUploader.workhorse_upload_path) do |clone_path|
|
||||
create_job_trace!(job, clone_path)
|
||||
end
|
||||
end
|
||||
|
||||
job.create_job_artifacts_trace!(
|
||||
project: job.project,
|
||||
file_type: :trace,
|
||||
file: file)
|
||||
ensure
|
||||
file&.close
|
||||
file&.unlink
|
||||
def clone_file!(src_stream, temp_dir)
|
||||
FileUtils.mkdir_p(temp_dir)
|
||||
Dir.mktmpdir('tmp-trace', temp_dir) do |dir_path|
|
||||
temp_path = File.join(dir_path, "job.log")
|
||||
size = IO.write(src_stream, temp_path)
|
||||
raise 'Not all saved' unless size == src_stream.size
|
||||
yield(temp_path)
|
||||
end
|
||||
end
|
||||
|
||||
def create_job_trace!(job, path)
|
||||
File.open(path) do |stream|
|
||||
job.create_job_artifacts_trace!(
|
||||
project: job.project,
|
||||
file_type: :trace,
|
||||
file: stream)
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_path
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
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')
|
||||
|
||||
job_ids = Ci::Build.complete.without_trace_artifact.pluck(:id)
|
||||
job_ids = job_ids.map { |build_id| [build_id] }
|
||||
|
||||
ArchiveLegacyTraceWorker.bulk_perform_async(job_ids)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue