blob: 3a6d0f6f8e5c5b254259c3cad06bdfeed2551e42 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
module Ci
class CreateTraceArtifactService < BaseService
def execute(job)
return if job.job_artifacts_trace
job.trace.read do |stream|
break unless stream.file?
temp_file!(JobArtifactUploader.workhorse_upload_path) do |temp_path|
FileUtils.cp(stream.path, temp_path)
create_job_trace!(job, temp_path)
FileUtils.rm(stream.path)
end
end
end
private
def create_job_trace!(job, path)
job.create_job_artifacts_trace!(
project: job.project,
file_type: :trace,
file: UploadedFile.new(path, 'job.log', 'application/octet-stream')
)
end
def temp_file!(temp_dir)
FileUtils.mkdir_p(temp_dir)
temp_file = Tempfile.new('trace-tmp-', temp_dir)
temp_file&.close
yield(temp_file.path)
ensure
temp_file&.close
temp_file&.unlink
end
end
end
|