summaryrefslogtreecommitdiff
path: root/app/uploaders/job_artifact_uploader.rb
blob: cc6e1927f9e7c1565c89e596b3774de69f507c59 (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
class JobArtifactUploader < ArtifactUploader
  def initialize(artifact, _field)
    @artifact = artifact
  end

  def size
    return super unless @artifact.size

    @artifact.size
  end

  private

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

  def default_path
    creation_date = job.created_at.utc.strftime('%Y_%m_%d')

    File.join(disk_hash[0..1], disk_hash[2..3], disk_hash,
              creation_date, job.id.to_s, @artifact.id.to_s)
  end

  def job
    @artifact.job
  end
end