2017-11-07 04:18:32 -05:00
|
|
|
class JobArtifactUploader < GitlabUploader
|
2018-01-29 12:57:34 -05:00
|
|
|
extend Workhorse::UploadPath
|
2017-11-07 04:18:32 -05:00
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
storage_options Gitlab.config.artifacts
|
2017-11-07 04:18:32 -05:00
|
|
|
|
2017-09-21 04:34:12 -04:00
|
|
|
def size
|
2017-11-23 10:57:27 -05:00
|
|
|
return super if model.size.nil?
|
2017-09-21 04:34:12 -04:00
|
|
|
|
2017-11-23 10:57:27 -05:00
|
|
|
model.size
|
2017-09-21 04:34:12 -04:00
|
|
|
end
|
|
|
|
|
2017-11-23 12:51:20 -05:00
|
|
|
def store_dir
|
2018-01-29 12:57:34 -05:00
|
|
|
dynamic_segment
|
2017-11-23 12:51:20 -05:00
|
|
|
end
|
|
|
|
|
2018-01-25 04:50:56 -05:00
|
|
|
def open
|
2018-01-26 12:00:29 -05:00
|
|
|
raise 'Only File System is supported' unless file_storage?
|
|
|
|
|
2018-01-29 11:56:12 -05:00
|
|
|
File.open(path, "rb") if path
|
|
|
|
end
|
|
|
|
|
2017-11-07 04:18:32 -05:00
|
|
|
private
|
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
def dynamic_segment
|
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
|