2018-02-02 08:59:43 -05:00
|
|
|
class JobArtifactUploader < GitlabUploader
|
|
|
|
extend Workhorse::UploadPath
|
|
|
|
include ObjectStorage::Concern
|
2017-11-07 04:18:32 -05:00
|
|
|
|
2018-04-03 12:47:33 -04:00
|
|
|
ObjectNotReadyError = Class.new(StandardError)
|
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
storage_options Gitlab.config.artifacts
|
2017-11-07 04:18:32 -05:00
|
|
|
|
2018-03-20 19:03:50 -04:00
|
|
|
def cached_size
|
|
|
|
return model.size if model.size.present? && !model.file_changed?
|
2017-09-21 04:34:12 -04:00
|
|
|
|
2018-03-20 19:03:50 -04:00
|
|
|
size
|
2017-09-21 04:34:12 -04:00
|
|
|
end
|
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
def store_dir
|
|
|
|
dynamic_segment
|
|
|
|
end
|
|
|
|
|
2018-02-06 09:18:32 -05:00
|
|
|
def open
|
2018-03-02 13:21:03 -05:00
|
|
|
if file_storage?
|
|
|
|
File.open(path, "rb") if path
|
|
|
|
else
|
2018-03-20 19:03:50 -04:00
|
|
|
::Gitlab::Ci::Trace::HttpIO.new(url, cached_size) if url
|
2018-03-02 13:21:03 -05:00
|
|
|
end
|
2018-02-06 09:18:32 -05:00
|
|
|
end
|
|
|
|
|
2017-11-07 04:18:32 -05:00
|
|
|
private
|
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
def dynamic_segment
|
2018-04-03 12:47:33 -04:00
|
|
|
raise ObjectNotReadyError, 'JobArtifact is not ready' unless model.id
|
|
|
|
|
2017-11-23 10:57:27 -05:00
|
|
|
creation_date = model.created_at.utc.strftime('%Y_%m_%d')
|
2017-09-21 04:34:12 -04:00
|
|
|
|
|
|
|
File.join(disk_hash[0..1], disk_hash[2..3], disk_hash,
|
2017-11-23 10:57:27 -05:00
|
|
|
creation_date, model.job_id.to_s, model.id.to_s)
|
2017-11-07 04:18:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def disk_hash
|
2017-11-23 10:57:27 -05:00
|
|
|
@disk_hash ||= Digest::SHA2.hexdigest(model.project_id.to_s)
|
2017-09-21 04:34:12 -04:00
|
|
|
end
|
|
|
|
end
|