Commit f0d7a2ff authored by Kamil Trzciński's avatar Kamil Trzciński Committed by Shinya Maeda

Proper fix for artifacts trace migration which is fully safe

parent fa31559a
......@@ -2,9 +2,11 @@ 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::CreateTraceArtifactService.new(job.project, job.user).execute(job)
job.trace.archive!
end
end
end
......@@ -93,8 +93,39 @@ module Gitlab
job.erase_old_trace!
end
def archive!
return if trace_artifact
if current_path
File.open(current_path) do |f|
archive_stream!(f)
f.unlink
end
elsif old_trace
StringIO(old_trace).tap do |stream|
archive_stream!(stream)
job.erase_old_trace!
end
end
end
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
job.create_job_artifacts_trace!(
project: job.project,
file_type: :trace,
file: file)
ensure
file&.close
file&.unlink
end
def ensure_path
return current_path if current_path
......
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