Welcome to mirror list, hosted at ThFree Co, Russian Federation.

job_artifact_uploader.rb « uploaders « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd86753479d496e2cab6955195abb3d2f3f790dd (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
38
39
40
41
class JobArtifactUploader < GitlabUploader
  extend Workhorse::UploadPath
  include ObjectStorage::Concern

  ObjectNotReadyError = Class.new(StandardError)

  storage_options Gitlab.config.artifacts

  def size
    return super if model.size.nil?

    model.size
  end

  def store_dir
    dynamic_segment
  end

  def open
    if file_storage?
      File.open(path, "rb") if path
    else
      ::Gitlab::Ci::Trace::HttpIO.new(url, size) if url
    end
  end

  private

  def dynamic_segment
    raise ObjectNotReadyError, 'JobArtifact is not ready' unless model.id

    creation_date = model.created_at.utc.strftime('%Y_%m_%d')

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

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