job_artifact_uploader.rb 663 Bytes
Newer Older
1
class JobArtifactUploader < GitlabUploader
2
  extend Workhorse::UploadPath
3

4
  storage_options Gitlab.config.artifacts
5

6
7
  def size
    return super if model.size.nil?
8

9
    model.size
10
  end
11

12
  def store_dir
13
    dynamic_segment
14
15
  end

Shinya Maeda's avatar
Shinya Maeda committed
16
  def open
Shinya Maeda's avatar
Shinya Maeda committed
17
18
    raise 'Only File System is supported' unless file_storage?

Shinya Maeda's avatar
Shinya Maeda committed
19
20
21
    File.open(path, "rb") if path
  end

22
  private
23

24
  def dynamic_segment
25
    creation_date = model.created_at.utc.strftime('%Y_%m_%d')
26
27

    File.join(disk_hash[0..1], disk_hash[2..3], disk_hash,
28
              creation_date, model.job_id.to_s, model.id.to_s)
29
30
31
  end

  def disk_hash
32
    @disk_hash ||= Digest::SHA2.hexdigest(model.project_id.to_s)
33
34
  end
end