2017-09-19 03:14:06 -04:00
|
|
|
# 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
|
2017-11-30 08:18:38 -05:00
|
|
|
job_artifacts_archive&.file || legacy_artifacts_file
|
2017-11-23 10:57:27 -05:00
|
|
|
end
|
|
|
|
|
2017-09-19 03:14:06 -04:00
|
|
|
def artifacts_metadata
|
2017-11-30 08:18:38 -05:00
|
|
|
job_artifacts_metadata&.file || legacy_artifacts_metadata
|
2017-09-19 03:14:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def artifacts?
|
|
|
|
!artifacts_expired? && artifacts_file.exists?
|
|
|
|
end
|
|
|
|
|
|
|
|
def artifacts_metadata?
|
|
|
|
artifacts? && artifacts_metadata.exists?
|
|
|
|
end
|
|
|
|
|
2017-09-21 04:34:12 -04:00
|
|
|
def artifacts_file_changed?
|
2017-11-30 08:18:38 -05:00
|
|
|
job_artifacts_archive&.file_changed? || attribute_changed?(:artifacts_file)
|
2017-09-19 03:14:06 -04:00
|
|
|
end
|
|
|
|
|
2017-09-21 04:34:12 -04:00
|
|
|
def remove_artifacts_file!
|
2017-11-30 08:18:38 -05:00
|
|
|
if job_artifacts_archive
|
|
|
|
job_artifacts_archive.destroy
|
2017-09-21 04:34:12 -04:00
|
|
|
else
|
2017-11-23 10:57:27 -05:00
|
|
|
remove_legacy_artifacts_file!
|
2017-09-21 04:34:12 -04:00
|
|
|
end
|
2017-09-19 03:14:06 -04:00
|
|
|
end
|
|
|
|
|
2017-09-21 04:34:12 -04:00
|
|
|
def remove_artifacts_metadata!
|
2017-11-30 08:18:38 -05:00
|
|
|
if job_artifacts_metadata
|
|
|
|
job_artifacts_metadata.destroy
|
2017-09-21 04:34:12 -04:00
|
|
|
else
|
2017-11-23 10:57:27 -05:00
|
|
|
remove_legacy_artifacts_metadata!
|
2017-09-21 04:34:12 -04:00
|
|
|
end
|
2017-09-19 03:14:06 -04:00
|
|
|
end
|
|
|
|
|
2017-09-21 04:34:12 -04:00
|
|
|
def artifacts_size
|
2018-01-25 09:04:53 -05:00
|
|
|
read_attribute(:artifacts_size).to_i + job_artifacts.sum(:size).to_i
|
2017-09-19 03:14:06 -04:00
|
|
|
end
|
|
|
|
end
|