2020-08-11 20:09:52 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
module Artifactable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2021-03-31 11:10:27 -04:00
|
|
|
include ObjectStorable
|
2020-08-27 11:10:21 -04:00
|
|
|
|
2021-03-31 11:10:27 -04:00
|
|
|
STORE_COLUMN = :file_store
|
|
|
|
NotSupportedAdapterError = Class.new(StandardError)
|
2020-08-11 20:09:52 -04:00
|
|
|
FILE_FORMAT_ADAPTERS = {
|
|
|
|
gzip: Gitlab::Ci::Build::Artifacts::Adapters::GzipStream,
|
|
|
|
raw: Gitlab::Ci::Build::Artifacts::Adapters::RawStream
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
included do
|
|
|
|
enum file_format: {
|
|
|
|
raw: 1,
|
|
|
|
zip: 2,
|
|
|
|
gzip: 3
|
|
|
|
}, _suffix: true
|
2020-09-01 08:11:01 -04:00
|
|
|
|
2020-12-22 07:10:09 -05:00
|
|
|
scope :expired_before, -> (timestamp) { where(arel_table[:expire_at].lt(timestamp)) }
|
2022-05-30 02:09:32 -04:00
|
|
|
scope :expired, -> { expired_before(Time.current) }
|
2021-03-31 11:10:27 -04:00
|
|
|
scope :project_id_in, ->(ids) { where(project_id: ids) }
|
2020-08-11 20:09:52 -04:00
|
|
|
end
|
2020-08-27 11:10:21 -04:00
|
|
|
|
|
|
|
def each_blob(&blk)
|
|
|
|
unless file_format_adapter_class
|
|
|
|
raise NotSupportedAdapterError, 'This file format requires a dedicated adapter'
|
|
|
|
end
|
|
|
|
|
|
|
|
file.open do |stream|
|
|
|
|
file_format_adapter_class.new(stream).each_blob(&blk)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def file_format_adapter_class
|
|
|
|
FILE_FORMAT_ADAPTERS[file_format.to_sym]
|
|
|
|
end
|
2020-08-11 20:09:52 -04:00
|
|
|
end
|
|
|
|
end
|
2021-04-01 14:13:56 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Ci::Artifactable.prepend_mod
|