artifact_migratable.rb 1.27 KB
Newer Older
1 2
# frozen_string_literal: true

3 4 5 6 7
# Adapter class to unify the interface between mounted uploaders and the
# Ci::Artifact model
# Meant to be prepended so the interface can stay the same
module ArtifactMigratable
  def artifacts_file
8
    job_artifacts_archive&.file || legacy_artifacts_file
9 10
  end

11
  def artifacts_metadata
12
    job_artifacts_metadata&.file || legacy_artifacts_metadata
13 14 15
  end

  def artifacts?
Shinya Maeda's avatar
Shinya Maeda committed
16
    !artifacts_expired? && artifacts_file&.exists?
17 18 19 20 21 22
  end

  def artifacts_metadata?
    artifacts? && artifacts_metadata.exists?
  end

23
  def artifacts_file_changed?
24
    job_artifacts_archive&.file_changed? || attribute_changed?(:artifacts_file)
25 26
  end

27
  def remove_artifacts_file!
28 29
    if job_artifacts_archive
      job_artifacts_archive.destroy
30
    else
31
      remove_legacy_artifacts_file!
32
    end
33 34
  end

35
  def remove_artifacts_metadata!
36 37
    if job_artifacts_metadata
      job_artifacts_metadata.destroy
38
    else
39
      remove_legacy_artifacts_metadata!
40
    end
41 42
  end

43
  def artifacts_size
44
    read_attribute(:artifacts_size).to_i + job_artifacts.sum(:size).to_i
45
  end
Shinya Maeda's avatar
Shinya Maeda committed
46 47 48 49 50 51 52 53 54 55 56 57

  def legacy_artifacts_file
    return unless Feature.enabled?(:ci_enable_legacy_artifacts)

    super
  end

  def legacy_artifacts_metadata
    return unless Feature.enabled?(:ci_enable_legacy_artifacts)

    super
  end
58
end