diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-01-27 02:00:29 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-02-06 15:50:08 +0900 |
commit | 5f6d826165aa975735cd543dba2b91999c115545 (patch) | |
tree | e1f2de2c8106a420e75c26302dbe340bcaf4bc8c | |
parent | 002f314f320c5731681297225fff5b528de88ed2 (diff) | |
download | gitlab-ce-5f6d826165aa975735cd543dba2b91999c115545.tar.gz |
Add CreateArtifactsTraceWorker
-rw-r--r-- | app/services/ci/create_artifacts_trace_service.rb | 16 | ||||
-rw-r--r-- | app/uploaders/job_artifact_uploader.rb | 8 | ||||
-rw-r--r-- | app/workers/build_finished_worker.rb | 1 | ||||
-rw-r--r-- | app/workers/create_artifacts_trace_worker.rb | 8 | ||||
-rw-r--r-- | lib/api/runner.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/ci/trace.rb | 12 |
6 files changed, 35 insertions, 21 deletions
diff --git a/app/services/ci/create_artifacts_trace_service.rb b/app/services/ci/create_artifacts_trace_service.rb new file mode 100644 index 00000000000..eefc2ae13ea --- /dev/null +++ b/app/services/ci/create_artifacts_trace_service.rb @@ -0,0 +1,16 @@ +module Ci + class CreateArtifactsTraceService < BaseService + def execute(job_id) + Ci::Build.find_by(id: job_id).try do |job| + return if job.job_artifacts_trace + + job.trace.read do |stream| + job.create_job_artifacts_trace!( + project: job.project, + file_type: :trace, + file: stream.path) if stream.file? + end + end + end + end +end diff --git a/app/uploaders/job_artifact_uploader.rb b/app/uploaders/job_artifact_uploader.rb index 4c814c6f501..57678dae9ca 100644 --- a/app/uploaders/job_artifact_uploader.rb +++ b/app/uploaders/job_artifact_uploader.rb @@ -14,11 +14,9 @@ class JobArtifactUploader < GitlabUploader end def open - if file_storage? - File.open(path, "rb") - else - raise 'Only File System is supported' - end + raise 'Only File System is supported' unless file_storage? + + File.open(path, "rb") end private diff --git a/app/workers/build_finished_worker.rb b/app/workers/build_finished_worker.rb index 97d80305bec..842ab7bbbe4 100644 --- a/app/workers/build_finished_worker.rb +++ b/app/workers/build_finished_worker.rb @@ -7,6 +7,7 @@ class BuildFinishedWorker def perform(build_id) Ci::Build.find_by(id: build_id).try do |build| BuildTraceSectionsWorker.perform_async(build.id) + CreateArtifactsTraceWorker.perform_async(build.id) BuildCoverageWorker.new.perform(build.id) BuildHooksWorker.new.perform(build.id) end diff --git a/app/workers/create_artifacts_trace_worker.rb b/app/workers/create_artifacts_trace_worker.rb new file mode 100644 index 00000000000..d73951b0905 --- /dev/null +++ b/app/workers/create_artifacts_trace_worker.rb @@ -0,0 +1,8 @@ +class CreateArtifactsTraceWorker + include ApplicationWorker + include PipelineQueue + + def perform(job_id) + Ci::CreateArtifactsTraceService.new.execute(job_id) + end +end diff --git a/lib/api/runner.rb b/lib/api/runner.rb index bab9d263e8d..1f80646a2ea 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -120,16 +120,7 @@ module API put '/:id' do job = authenticate_job! - if params[:trace] - # Overwrite live-trace by full-trace - job.trace.set(params[:trace]) - - # Move full-trace to JobArtifactUploader#default_path - job.build_job_artifacts_trace( - project: job.project, - file_type: :trace, - file: UploadedFile.new(job.trace.current_path, 'trace.log')) - end + job.trace.set(params[:trace]) if params[:trace] Gitlab::Metrics.add_event(:update_build, project: job.project.full_path) diff --git a/lib/gitlab/ci/trace.rb b/lib/gitlab/ci/trace.rb index 307e3bf1c8f..27f5869770e 100644 --- a/lib/gitlab/ci/trace.rb +++ b/lib/gitlab/ci/trace.rb @@ -101,12 +101,6 @@ module Gitlab job.erase_old_trace! end - def current_path - @current_path ||= paths.find do |trace_path| - File.exist?(trace_path) - end - end - private def ensure_path @@ -122,6 +116,12 @@ module Gitlab end end + def current_path + @current_path ||= paths.find do |trace_path| + File.exist?(trace_path) + end + end + ## # This method doesn't include the latest path, which is JobArtifactUploader#default_path, # Because, in EE, traces can be moved to ObjectStorage, so checking paths in Filestorage doesn't make sense. |