job_artifact.rb 760 Bytes
Newer Older
1
2
3
4
5
module Ci
  class JobArtifact < ActiveRecord::Base
    extend Gitlab::Ci::Model

    belongs_to :project
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
6
    belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id
7
8
9
10
11

    before_save :set_size, if: :file_changed?

    mount_uploader :file, JobArtifactUploader

Shinya Maeda's avatar
Shinya Maeda committed
12
13
    delegate :open, :exists?, to: :file

14
15
    enum file_type: {
      archive: 1,
Shinya Maeda's avatar
Shinya Maeda committed
16
17
      metadata: 2,
      trace: 3
18
19
20
21
22
23
24
25
26
    }

    def self.artifacts_size_for(project)
      self.where(project: project).sum(:size)
    end

    def set_size
      self.size = file.size
    end
27
28
29
30
31
32
33
34
35
36
37

    def expire_in
      expire_at - Time.now if expire_at
    end

    def expire_in=(value)
      self.expire_at =
        if value
          ChronicDuration.parse(value)&.seconds&.from_now
        end
    end
38
39
  end
end