2018-08-03 03:15:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-21 04:34:12 -04:00
|
|
|
module Ci
|
2021-08-03 02:08:50 -04:00
|
|
|
class JobArtifact < Ci::ApplicationRecord
|
2021-12-02 22:14:42 -05:00
|
|
|
include IgnorableColumns
|
2017-12-08 04:09:06 -05:00
|
|
|
include AfterCommitQueue
|
2018-02-21 11:43:21 -05:00
|
|
|
include ObjectStorage::BackgroundMove
|
2019-04-19 05:37:14 -04:00
|
|
|
include UpdateProjectStatistics
|
2020-05-20 20:08:06 -04:00
|
|
|
include UsageStatistics
|
2019-09-18 17:06:34 -04:00
|
|
|
include Sortable
|
2020-08-11 20:09:52 -04:00
|
|
|
include Artifactable
|
2020-08-13 14:10:36 -04:00
|
|
|
include FileStoreMounter
|
2020-12-22 07:10:09 -05:00
|
|
|
include EachBatch
|
2021-10-29 08:14:45 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
2017-09-21 04:34:12 -04:00
|
|
|
|
2018-09-27 17:15:08 -04:00
|
|
|
NON_ERASABLE_FILE_TYPES = %w[trace].freeze
|
2022-08-01 11:11:13 -04:00
|
|
|
|
|
|
|
REPORT_FILE_TYPES = {
|
|
|
|
sast: %w[sast],
|
|
|
|
secret_detection: %w[secret_detection],
|
|
|
|
test: %w[junit],
|
|
|
|
accessibility: %w[accessibility],
|
|
|
|
coverage: %w[cobertura],
|
|
|
|
codequality: %w[codequality],
|
|
|
|
terraform: %w[terraform]
|
|
|
|
}.freeze
|
|
|
|
|
2018-09-27 17:15:08 -04:00
|
|
|
DEFAULT_FILE_NAMES = {
|
|
|
|
archive: nil,
|
|
|
|
metadata: nil,
|
|
|
|
trace: nil,
|
2020-01-15 16:08:48 -05:00
|
|
|
metrics_referee: nil,
|
|
|
|
network_referee: nil,
|
2018-09-27 17:15:08 -04:00
|
|
|
junit: 'junit.xml',
|
2020-04-22 23:09:51 -04:00
|
|
|
accessibility: 'gl-accessibility.json',
|
2018-11-05 11:32:03 -05:00
|
|
|
codequality: 'gl-code-quality-report.json',
|
2018-09-27 17:15:08 -04:00
|
|
|
sast: 'gl-sast-report.json',
|
2020-05-29 20:08:33 -04:00
|
|
|
secret_detection: 'gl-secret-detection-report.json',
|
2018-09-27 17:15:08 -04:00
|
|
|
dependency_scanning: 'gl-dependency-scanning-report.json',
|
|
|
|
container_scanning: 'gl-container-scanning-report.json',
|
2021-07-06 05:07:05 -04:00
|
|
|
cluster_image_scanning: 'gl-cluster-image-scanning-report.json',
|
2018-10-07 04:22:40 -04:00
|
|
|
dast: 'gl-dast-report.json',
|
2020-01-09 13:07:52 -05:00
|
|
|
license_scanning: 'gl-license-scanning-report.json',
|
2019-04-16 07:06:52 -04:00
|
|
|
performance: 'performance.json',
|
2020-07-09 11:08:59 -04:00
|
|
|
browser_performance: 'browser-performance.json',
|
2020-07-10 08:09:15 -04:00
|
|
|
load_performance: 'load-performance.json',
|
2020-01-28 13:08:35 -05:00
|
|
|
metrics: 'metrics.txt',
|
2020-03-13 17:09:38 -04:00
|
|
|
lsif: 'lsif.json',
|
2020-03-17 14:09:44 -04:00
|
|
|
dotenv: '.env',
|
2020-03-24 14:07:55 -04:00
|
|
|
cobertura: 'cobertura-coverage.xml',
|
2020-05-11 23:09:31 -04:00
|
|
|
terraform: 'tfplan.json',
|
2022-05-05 05:08:00 -04:00
|
|
|
cluster_applications: 'gl-cluster-applications.json', # DEPRECATED: https://gitlab.com/gitlab-org/gitlab/-/issues/361094
|
2020-06-30 11:08:48 -04:00
|
|
|
requirements: 'requirements.json',
|
2020-10-07 17:08:21 -04:00
|
|
|
coverage_fuzzing: 'gl-coverage-fuzzing.json',
|
2022-08-02 11:09:10 -04:00
|
|
|
api_fuzzing: 'gl-api-fuzzing-report.json',
|
|
|
|
cyclonedx: 'gl-sbom.cdx.zip'
|
2018-09-27 17:15:08 -04:00
|
|
|
}.freeze
|
|
|
|
|
2019-05-20 18:56:19 -04:00
|
|
|
INTERNAL_TYPES = {
|
2018-09-27 17:15:08 -04:00
|
|
|
archive: :zip,
|
|
|
|
metadata: :gzip,
|
2019-05-20 18:56:19 -04:00
|
|
|
trace: :raw
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
REPORT_TYPES = {
|
2018-09-27 17:15:08 -04:00
|
|
|
junit: :gzip,
|
2019-04-16 07:06:52 -04:00
|
|
|
metrics: :gzip,
|
2020-01-15 16:08:48 -05:00
|
|
|
metrics_referee: :gzip,
|
|
|
|
network_referee: :gzip,
|
2020-03-13 17:09:38 -04:00
|
|
|
dotenv: :gzip,
|
2020-03-17 14:09:44 -04:00
|
|
|
cobertura: :gzip,
|
2022-05-05 05:08:00 -04:00
|
|
|
cluster_applications: :gzip, # DEPRECATED: https://gitlab.com/gitlab-org/gitlab/-/issues/361094
|
2020-05-15 14:07:52 -04:00
|
|
|
lsif: :zip,
|
2018-10-15 06:17:21 -04:00
|
|
|
|
2020-10-12 08:08:37 -04:00
|
|
|
# Security reports and license scanning reports are raw artifacts
|
|
|
|
# because they used to be fetched by the frontend, but this is not the case anymore.
|
2018-10-15 06:17:21 -04:00
|
|
|
sast: :raw,
|
2020-05-29 20:08:33 -04:00
|
|
|
secret_detection: :raw,
|
2018-10-15 06:17:21 -04:00
|
|
|
dependency_scanning: :raw,
|
|
|
|
container_scanning: :raw,
|
2021-07-06 05:07:05 -04:00
|
|
|
cluster_image_scanning: :raw,
|
2018-10-07 04:22:40 -04:00
|
|
|
dast: :raw,
|
2020-01-08 10:08:01 -05:00
|
|
|
license_scanning: :raw,
|
2020-10-12 08:08:37 -04:00
|
|
|
|
|
|
|
# All these file formats use `raw` as we need to store them uncompressed
|
|
|
|
# for Frontend to fetch the files and do analysis
|
|
|
|
# When they will be only used by backend, they can be `gzipped`.
|
|
|
|
accessibility: :raw,
|
|
|
|
codequality: :raw,
|
2020-03-24 14:07:55 -04:00
|
|
|
performance: :raw,
|
2020-07-09 11:08:59 -04:00
|
|
|
browser_performance: :raw,
|
2020-07-10 08:09:15 -04:00
|
|
|
load_performance: :raw,
|
2020-06-08 08:08:26 -04:00
|
|
|
terraform: :raw,
|
2020-06-30 11:08:48 -04:00
|
|
|
requirements: :raw,
|
2020-10-07 17:08:21 -04:00
|
|
|
coverage_fuzzing: :raw,
|
2022-08-02 11:09:10 -04:00
|
|
|
api_fuzzing: :raw,
|
|
|
|
cyclonedx: :zip
|
2018-09-27 17:15:08 -04:00
|
|
|
}.freeze
|
2018-07-27 01:04:35 -04:00
|
|
|
|
2020-05-14 08:08:21 -04:00
|
|
|
DOWNLOADABLE_TYPES = %w[
|
|
|
|
accessibility
|
2020-10-07 17:08:21 -04:00
|
|
|
api_fuzzing
|
2020-05-14 08:08:21 -04:00
|
|
|
archive
|
|
|
|
cobertura
|
|
|
|
codequality
|
|
|
|
container_scanning
|
|
|
|
dast
|
|
|
|
dependency_scanning
|
|
|
|
dotenv
|
|
|
|
junit
|
|
|
|
license_scanning
|
|
|
|
lsif
|
|
|
|
metrics
|
|
|
|
performance
|
2020-07-09 11:08:59 -04:00
|
|
|
browser_performance
|
2020-07-10 08:09:15 -04:00
|
|
|
load_performance
|
2020-05-14 08:08:21 -04:00
|
|
|
sast
|
2020-06-11 08:08:54 -04:00
|
|
|
secret_detection
|
2020-06-08 08:08:26 -04:00
|
|
|
requirements
|
2021-07-06 05:07:05 -04:00
|
|
|
cluster_image_scanning
|
2022-08-02 11:09:10 -04:00
|
|
|
cyclonedx
|
2020-05-14 08:08:21 -04:00
|
|
|
].freeze
|
|
|
|
|
2019-05-20 18:56:19 -04:00
|
|
|
TYPE_AND_FORMAT_PAIRS = INTERNAL_TYPES.merge(REPORT_TYPES).freeze
|
|
|
|
|
2020-07-06 11:08:42 -04:00
|
|
|
PLAN_LIMIT_PREFIX = 'ci_max_artifact_size_'
|
|
|
|
|
2017-09-21 04:34:12 -04:00
|
|
|
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
|
|
|
|
2021-12-02 22:14:42 -05:00
|
|
|
# We will start using this column once we complete https://gitlab.com/gitlab-org/gitlab/-/issues/285597
|
|
|
|
ignore_column :original_filename, remove_with: '14.7', remove_after: '2022-11-22'
|
|
|
|
|
2022-06-10 11:09:22 -04:00
|
|
|
mount_file_store_uploader JobArtifactUploader, skip_store_file: true
|
2018-04-13 04:20:07 -04:00
|
|
|
|
2022-06-10 11:09:22 -04:00
|
|
|
after_save :store_file_in_transaction!, unless: :store_after_commit?
|
|
|
|
after_commit :store_file_after_transaction!, on: [:create, :update], if: :store_after_commit?
|
2021-10-29 08:14:45 -04:00
|
|
|
|
2018-07-27 01:04:35 -04:00
|
|
|
validates :file_format, presence: true, unless: :trace?, on: :create
|
2020-05-16 11:08:12 -04:00
|
|
|
validate :validate_file_format!, unless: :trace?, on: :create
|
2020-04-14 11:09:44 -04:00
|
|
|
before_save :set_size, if: :file_changed?
|
2017-09-21 04:34:12 -04:00
|
|
|
|
2020-04-14 11:09:44 -04:00
|
|
|
update_project_statistics project_statistics_name: :build_artifacts_size
|
|
|
|
|
2020-06-04 08:08:21 -04:00
|
|
|
scope :not_expired, -> { where('expire_at IS NULL OR expire_at > ?', Time.current) }
|
2020-02-23 22:09:05 -05:00
|
|
|
scope :for_sha, ->(sha, project_id) { joins(job: :pipeline).where(ci_pipelines: { sha: sha, project_id: project_id }) }
|
2021-11-18 19:09:40 -05:00
|
|
|
scope :for_job_ids, ->(job_ids) { where(job_id: job_ids) }
|
2020-03-24 14:07:55 -04:00
|
|
|
scope :for_job_name, ->(name) { joins(:job).where(ci_builds: { name: name }) }
|
2022-05-18 17:07:37 -04:00
|
|
|
scope :created_at_before, ->(time) { where(arel_table[:created_at].lteq(time)) }
|
2022-05-30 11:08:03 -04:00
|
|
|
scope :id_before, ->(id) { where(arel_table[:id].lteq(id)) }
|
2022-05-18 17:07:37 -04:00
|
|
|
scope :id_after, ->(id) { where(arel_table[:id].gt(id)) }
|
2022-05-30 11:08:03 -04:00
|
|
|
scope :ordered_by_id, -> { order(:id) }
|
2017-12-08 04:09:06 -05:00
|
|
|
|
2021-03-09 07:08:52 -05:00
|
|
|
scope :with_job, -> { joins(:job).includes(:job) }
|
2020-12-20 19:10:18 -05:00
|
|
|
|
2018-09-27 17:15:08 -04:00
|
|
|
scope :with_file_types, -> (file_types) do
|
|
|
|
types = self.file_types.select { |file_type| file_types.include?(file_type) }.values
|
|
|
|
|
|
|
|
where(file_type: types)
|
|
|
|
end
|
|
|
|
|
2022-08-01 11:11:13 -04:00
|
|
|
REPORT_FILE_TYPES.each do |report_type, file_types|
|
|
|
|
scope "#{report_type}_reports", -> do
|
|
|
|
with_file_types(file_types)
|
|
|
|
end
|
2021-02-10 04:09:38 -05:00
|
|
|
end
|
|
|
|
|
2022-08-01 11:11:13 -04:00
|
|
|
scope :all_reports, -> do
|
|
|
|
with_file_types(REPORT_TYPES.keys.map(&:to_s))
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
|
2018-09-27 17:15:08 -04:00
|
|
|
scope :erasable, -> do
|
2022-01-13 10:14:46 -05:00
|
|
|
where(file_type: self.erasable_file_types)
|
2018-07-27 01:04:35 -04:00
|
|
|
end
|
|
|
|
|
2020-06-04 08:08:21 -04:00
|
|
|
scope :downloadable, -> { where(file_type: DOWNLOADABLE_TYPES) }
|
2020-12-22 07:10:09 -05:00
|
|
|
scope :unlocked, -> { joins(job: :pipeline).merge(::Ci::Pipeline.unlocked) }
|
2022-04-06 14:08:19 -04:00
|
|
|
scope :order_expired_asc, -> { order(expire_at: :asc) }
|
2022-05-18 17:07:37 -04:00
|
|
|
scope :with_destroy_preloads, -> { includes(project: [:route, :statistics, :build_artifacts_size_refresh]) }
|
2019-01-17 01:06:37 -05:00
|
|
|
|
2021-06-17 11:10:03 -04:00
|
|
|
scope :for_project, ->(project) { where(project_id: project) }
|
|
|
|
scope :created_in_time_range, ->(from: nil, to: nil) { where(created_at: from..to) }
|
2019-08-28 10:26:42 -04:00
|
|
|
|
2018-07-18 17:46:56 -04:00
|
|
|
delegate :filename, :exists?, :open, to: :file
|
2018-02-06 09:18:32 -05:00
|
|
|
|
2017-09-21 04:34:12 -04:00
|
|
|
enum file_type: {
|
|
|
|
archive: 1,
|
2018-02-06 09:18:32 -05:00
|
|
|
metadata: 2,
|
2018-07-27 01:04:35 -04:00
|
|
|
trace: 3,
|
2018-09-27 17:15:08 -04:00
|
|
|
junit: 4,
|
|
|
|
sast: 5, ## EE-specific
|
|
|
|
dependency_scanning: 6, ## EE-specific
|
|
|
|
container_scanning: 7, ## EE-specific
|
2018-10-02 13:01:26 -04:00
|
|
|
dast: 8, ## EE-specific
|
2018-10-07 04:22:40 -04:00
|
|
|
codequality: 9, ## EE-specific
|
2021-06-14 11:09:48 -04:00
|
|
|
license_scanning: 101, ## EE-specific
|
2020-07-09 11:08:59 -04:00
|
|
|
performance: 11, ## EE-specific till 13.2
|
2020-01-15 16:08:48 -05:00
|
|
|
metrics: 12, ## EE-specific
|
|
|
|
metrics_referee: 13, ## runner referees
|
2020-01-28 13:08:35 -05:00
|
|
|
network_referee: 14, ## runner referees
|
2020-03-13 17:09:38 -04:00
|
|
|
lsif: 15, # LSIF data for code navigation
|
2020-03-17 14:09:44 -04:00
|
|
|
dotenv: 16,
|
2020-03-24 14:07:55 -04:00
|
|
|
cobertura: 17,
|
2020-04-22 23:09:51 -04:00
|
|
|
terraform: 18, # Transformed json
|
2020-05-11 23:09:31 -04:00
|
|
|
accessibility: 19,
|
2020-05-29 20:08:33 -04:00
|
|
|
cluster_applications: 20,
|
2020-06-08 08:08:26 -04:00
|
|
|
secret_detection: 21, ## EE-specific
|
2020-06-30 11:08:48 -04:00
|
|
|
requirements: 22, ## EE-specific
|
2020-07-09 11:08:59 -04:00
|
|
|
coverage_fuzzing: 23, ## EE-specific
|
2020-07-10 08:09:15 -04:00
|
|
|
browser_performance: 24, ## EE-specific
|
2020-10-07 17:08:21 -04:00
|
|
|
load_performance: 25, ## EE-specific
|
2021-07-06 05:07:05 -04:00
|
|
|
api_fuzzing: 26, ## EE-specific
|
2022-08-02 11:09:10 -04:00
|
|
|
cluster_image_scanning: 27, ## EE-specific
|
|
|
|
cyclonedx: 28 ## EE-specific
|
2017-09-21 04:34:12 -04:00
|
|
|
}
|
|
|
|
|
2018-08-17 00:33:15 -04:00
|
|
|
# `file_location` indicates where actual files are stored.
|
|
|
|
# Ideally, actual files should be stored in the same directory, and use the same
|
|
|
|
# convention to generate its path. However, sometimes we can't do so due to backward-compatibility.
|
|
|
|
#
|
|
|
|
# legacy_path ... The actual file is stored at a path consists of a timestamp
|
|
|
|
# and raw project/model IDs. Those rows were migrated from
|
|
|
|
# `ci_builds.artifacts_file` and `ci_builds.artifacts_metadata`
|
|
|
|
# hashed_path ... The actual file is stored at a path consists of a SHA2 based on the project ID.
|
|
|
|
# This is the default value.
|
|
|
|
enum file_location: {
|
|
|
|
legacy_path: 1,
|
|
|
|
hashed_path: 2
|
|
|
|
}
|
|
|
|
|
2021-09-05 23:11:02 -04:00
|
|
|
# `locked` will be populated from the source of truth on Ci::Pipeline
|
|
|
|
# in order to clean up expired job artifacts in a performant way.
|
|
|
|
# The values should be the same as `Ci::Pipeline.lockeds` with the
|
|
|
|
# additional value of `unknown` to indicate rows that have not
|
|
|
|
# yet been populated from the parent Ci::Pipeline
|
|
|
|
enum locked: {
|
|
|
|
unlocked: 0,
|
|
|
|
artifacts_locked: 1,
|
|
|
|
unknown: 2
|
|
|
|
}, _prefix: :artifact
|
|
|
|
|
2020-05-16 11:08:12 -04:00
|
|
|
def validate_file_format!
|
2018-07-27 01:04:35 -04:00
|
|
|
unless TYPE_AND_FORMAT_PAIRS[self.file_type&.to_sym] == self.file_format&.to_sym
|
2020-03-03 04:07:54 -05:00
|
|
|
errors.add(:base, _('Invalid file format with specified file type'))
|
2018-07-27 01:04:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-17 02:09:11 -04:00
|
|
|
def self.associated_file_types_for(file_type)
|
|
|
|
return unless file_types.include?(file_type)
|
|
|
|
|
|
|
|
[file_type]
|
|
|
|
end
|
|
|
|
|
2022-01-13 10:14:46 -05:00
|
|
|
def self.erasable_file_types
|
|
|
|
self.file_types.keys - NON_ERASABLE_FILE_TYPES
|
|
|
|
end
|
|
|
|
|
2019-09-18 17:06:34 -04:00
|
|
|
def self.total_size
|
|
|
|
self.sum(:size)
|
|
|
|
end
|
|
|
|
|
2017-09-21 04:34:12 -04:00
|
|
|
def self.artifacts_size_for(project)
|
|
|
|
self.where(project: project).sum(:size)
|
|
|
|
end
|
|
|
|
|
2022-04-06 14:08:19 -04:00
|
|
|
def self.pluck_job_id
|
|
|
|
pluck(:job_id)
|
|
|
|
end
|
|
|
|
|
2021-05-14 08:10:58 -04:00
|
|
|
##
|
|
|
|
# FastDestroyAll concerns
|
|
|
|
# rubocop: disable CodeReuse/ServiceClass
|
|
|
|
def self.begin_fast_destroy
|
|
|
|
service = ::Ci::JobArtifacts::DestroyAssociationsService.new(self)
|
|
|
|
service.destroy_records
|
|
|
|
service
|
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ServiceClass
|
|
|
|
|
|
|
|
##
|
|
|
|
# FastDestroyAll concerns
|
|
|
|
def self.finalize_fast_destroy(service)
|
|
|
|
service.update_statistics
|
|
|
|
end
|
|
|
|
|
2018-02-21 11:43:21 -05:00
|
|
|
def local_store?
|
|
|
|
[nil, ::JobArtifactUploader::Store::LOCAL].include?(self.file_store)
|
|
|
|
end
|
|
|
|
|
2018-08-17 00:33:15 -04:00
|
|
|
def hashed_path?
|
2018-09-05 12:12:46 -04:00
|
|
|
return true if trace? # ArchiveLegacyTraces background migration might not have `file_location` column
|
|
|
|
|
|
|
|
super || self.file_location.nil?
|
2018-08-17 00:33:15 -04:00
|
|
|
end
|
|
|
|
|
2020-06-04 08:08:21 -04:00
|
|
|
def expired?
|
|
|
|
expire_at.present? && expire_at < Time.current
|
|
|
|
end
|
|
|
|
|
|
|
|
def expiring?
|
|
|
|
expire_at.present? && expire_at > Time.current
|
|
|
|
end
|
|
|
|
|
2017-12-03 06:02:11 -05:00
|
|
|
def expire_in
|
2020-05-22 05:08:09 -04:00
|
|
|
expire_at - Time.current if expire_at
|
2017-12-03 06:02:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def expire_in=(value)
|
|
|
|
self.expire_at =
|
|
|
|
if value
|
2022-06-24 20:08:03 -04:00
|
|
|
::Gitlab::Ci::Build::DurationParser.new(value).seconds_from_now
|
2017-12-03 06:02:11 -05:00
|
|
|
end
|
|
|
|
end
|
2018-03-20 19:03:50 -04:00
|
|
|
|
2022-05-11 20:09:17 -04:00
|
|
|
def stored?
|
2021-04-06 08:09:21 -04:00
|
|
|
file&.file&.exists?
|
|
|
|
end
|
|
|
|
|
2019-07-18 05:22:46 -04:00
|
|
|
def self.archived_trace_exists_for?(job_id)
|
2022-05-11 20:09:17 -04:00
|
|
|
where(job_id: job_id).trace.take&.stored?
|
2019-07-18 05:22:46 -04:00
|
|
|
end
|
|
|
|
|
2020-07-06 11:08:42 -04:00
|
|
|
def self.max_artifact_size(type:, project:)
|
2020-07-17 20:09:34 -04:00
|
|
|
limit_name = "#{PLAN_LIMIT_PREFIX}#{type}"
|
|
|
|
|
|
|
|
max_size = project.actual_limits.limit_for(
|
|
|
|
limit_name,
|
|
|
|
alternate_limit: -> { project.closest_setting(:max_artifacts_size) }
|
|
|
|
)
|
2020-07-06 11:08:42 -04:00
|
|
|
|
|
|
|
max_size&.megabytes.to_i
|
|
|
|
end
|
|
|
|
|
2021-03-12 16:09:12 -05:00
|
|
|
def to_deleted_object_attrs(pick_up_at = nil)
|
2020-10-13 11:08:53 -04:00
|
|
|
{
|
|
|
|
file_store: file_store,
|
|
|
|
store_dir: file.store_dir.to_s,
|
|
|
|
file: file_identifier,
|
2021-03-12 16:09:12 -05:00
|
|
|
pick_up_at: pick_up_at || expire_at || Time.current
|
2020-10-13 11:08:53 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-10-29 08:14:45 -04:00
|
|
|
def store_after_commit?
|
|
|
|
strong_memoize(:store_after_commit) do
|
2022-01-19 13:14:01 -05:00
|
|
|
trace? && JobArtifactUploader.direct_upload_enabled?
|
2021-10-29 08:14:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-20 19:03:50 -04:00
|
|
|
private
|
|
|
|
|
2022-06-10 11:09:22 -04:00
|
|
|
def store_file_in_transaction!
|
|
|
|
store_file_now! if saved_change_to_file?
|
2021-10-29 08:14:45 -04:00
|
|
|
|
2022-06-10 11:09:22 -04:00
|
|
|
file_stored_in_transaction_hooks
|
|
|
|
end
|
|
|
|
|
|
|
|
def store_file_after_transaction!
|
|
|
|
store_file_now! if previous_changes.key?(:file)
|
|
|
|
|
|
|
|
file_stored_after_transaction_hooks
|
|
|
|
end
|
|
|
|
|
|
|
|
# method overriden in EE
|
|
|
|
def file_stored_after_transaction_hooks
|
|
|
|
end
|
|
|
|
|
|
|
|
# method overriden in EE
|
|
|
|
def file_stored_in_transaction_hooks
|
2021-10-29 08:14:45 -04:00
|
|
|
end
|
|
|
|
|
2018-03-20 19:03:50 -04:00
|
|
|
def set_size
|
|
|
|
self.size = file.size
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_destroyed?
|
|
|
|
# Use job.project to avoid extra DB query for project
|
|
|
|
job.project.pending_delete?
|
|
|
|
end
|
2017-09-21 04:34:12 -04:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Ci::JobArtifact.prepend_mod_with('Ci::JobArtifact')
|