2017-09-21 04:34:12 -04:00
|
|
|
module Ci
|
|
|
|
class JobArtifact < ActiveRecord::Base
|
|
|
|
extend Gitlab::Ci::Model
|
|
|
|
|
|
|
|
belongs_to :project
|
2017-11-02 14:38:25 -04:00
|
|
|
belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id
|
2017-09-21 04:34:12 -04:00
|
|
|
|
|
|
|
before_save :set_size, if: :file_changed?
|
|
|
|
|
|
|
|
mount_uploader :file, JobArtifactUploader
|
|
|
|
|
2018-01-25 04:50:56 -05:00
|
|
|
delegate :open, :exists?, to: :file
|
|
|
|
|
2017-09-21 04:34:12 -04:00
|
|
|
enum file_type: {
|
|
|
|
archive: 1,
|
2018-01-25 04:50:56 -05:00
|
|
|
metadata: 2,
|
|
|
|
trace: 3
|
2017-09-21 04:34:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
def self.artifacts_size_for(project)
|
|
|
|
self.where(project: project).sum(:size)
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_size
|
|
|
|
self.size = file.size
|
|
|
|
end
|
2017-12-03 06:02:11 -05:00
|
|
|
|
|
|
|
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
|
2017-09-21 04:34:12 -04:00
|
|
|
end
|
|
|
|
end
|