diff options
| author | Kamil TrzciĆski <ayufan@ayufan.eu> | 2018-02-23 13:08:38 +0100 |
|---|---|---|
| committer | Shinya Maeda <shinya@gitlab.com> | 2018-03-06 21:43:19 +0900 |
| commit | f0d7a2ffc419e5e4893f9161c008d4ead5d3a660 (patch) | |
| tree | b249173d7f2a508b61848993dc65068e7c399232 | |
| parent | fa31559a37bfe394dedf4078789f1540e01fc5c7 (diff) | |
| download | gitlab-ce-f0d7a2ffc419e5e4893f9161c008d4ead5d3a660.tar.gz | |
Proper fix for artifacts trace migration which is fully safe
| -rw-r--r-- | app/workers/create_trace_artifact_worker.rb | 4 | ||||
| -rw-r--r-- | lib/gitlab/ci/trace.rb | 31 |
2 files changed, 34 insertions, 1 deletions
diff --git a/app/workers/create_trace_artifact_worker.rb b/app/workers/create_trace_artifact_worker.rb index 11cda58021e..3283e8d79f0 100644 --- a/app/workers/create_trace_artifact_worker.rb +++ b/app/workers/create_trace_artifact_worker.rb @@ -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 diff --git a/lib/gitlab/ci/trace.rb b/lib/gitlab/ci/trace.rb index f2e5124c8a8..defc8160121 100644 --- a/lib/gitlab/ci/trace.rb +++ b/lib/gitlab/ci/trace.rb @@ -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 |
