2018-11-08 19:23:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
class JobArtifactUploader < GitlabUploader
|
|
|
|
extend Workhorse::UploadPath
|
2018-05-09 12:01:36 +05:30
|
|
|
include ObjectStorage::Concern
|
2022-11-25 23:54:43 +05:30
|
|
|
include ObjectStorage::CDN::Concern
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
UnknownFileLocationError = Class.new(StandardError)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
storage_options Gitlab.config.artifacts
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
alias_method :upload, :model
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
def cached_size
|
|
|
|
return model.size if model.size.present? && !model.file_changed?
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
size
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def store_dir
|
|
|
|
dynamic_segment
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def dynamic_segment
|
2020-11-05 12:06:23 +05:30
|
|
|
# This now tests model.created_at because it can for some reason be nil in the test suite,
|
|
|
|
# and it's not clear if this is intentional or not
|
|
|
|
raise ObjectNotReadyError, 'JobArtifact is not ready' unless model.id && model.created_at
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
if model.hashed_path?
|
|
|
|
hashed_path
|
|
|
|
elsif model.legacy_path?
|
|
|
|
legacy_path
|
|
|
|
else
|
|
|
|
raise UnknownFileLocationError
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
def hashed_path
|
2020-10-24 23:57:45 +05:30
|
|
|
Gitlab::HashedPath.new(model.created_at.utc.strftime('%Y_%m_%d'), model.job_id, model.id, root_hash: model.project_id)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def legacy_path
|
|
|
|
File.join(model.created_at.utc.strftime('%Y_%m'), model.project_id.to_s, model.job_id.to_s)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|