Commit 15a3481e authored by Yannis Roussos's avatar Yannis Roussos

Merge branch 'mc/fix-artifact-expiry-background-migration-query' into 'master'

Use new temp index for backfilling artifact expiry

See merge request gitlab-org/gitlab!55091
parents 91cb8558 b42e33db
...@@ -6,9 +6,9 @@ module Gitlab ...@@ -6,9 +6,9 @@ module Gitlab
class BackfillArtifactExpiryDate class BackfillArtifactExpiryDate
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
BATCH_SIZE = 1_000 SWITCH_DATE = Date.new(2020, 06, 22).freeze
DEFAULT_EXPIRATION_SWITCH_DATE = Date.new(2020, 6, 22).freeze
OLD_ARTIFACT_AGE = 15.months OLD_ARTIFACT_AGE = 15.months
BATCH_SIZE = 1_000
OLD_ARTIFACT_EXPIRY_OFFSET = 3.months OLD_ARTIFACT_EXPIRY_OFFSET = 3.months
RECENT_ARTIFACT_EXPIRY_OFFSET = 1.year RECENT_ARTIFACT_EXPIRY_OFFSET = 1.year
...@@ -18,16 +18,17 @@ module Gitlab ...@@ -18,16 +18,17 @@ module Gitlab
self.table_name = 'ci_job_artifacts' self.table_name = 'ci_job_artifacts'
scope :between, -> (start_id, end_id) { where(id: start_id..end_id) }
scope :before_default_expiration_switch, -> { where('created_at < ?', DEFAULT_EXPIRATION_SWITCH_DATE) }
scope :without_expiry_date, -> { where(expire_at: nil) } scope :without_expiry_date, -> { where(expire_at: nil) }
scope :before_switch, -> { where("date(created_at AT TIME ZONE 'UTC') < ?::date", SWITCH_DATE) }
scope :between, -> (start_id, end_id) { where(id: start_id..end_id) }
scope :old, -> { where(self.arel_table[:created_at].lt(OLD_ARTIFACT_AGE.ago)) } scope :old, -> { where(self.arel_table[:created_at].lt(OLD_ARTIFACT_AGE.ago)) }
scope :recent, -> { where(self.arel_table[:created_at].gt(OLD_ARTIFACT_AGE.ago)) } scope :recent, -> { where(self.arel_table[:created_at].gt(OLD_ARTIFACT_AGE.ago)) }
end end
def perform(start_id, end_id) def perform(start_id, end_id)
Ci::JobArtifact.between(start_id, end_id) Ci::JobArtifact
.without_expiry_date.before_default_expiration_switch .without_expiry_date.before_switch
.between(start_id, end_id)
.each_batch(of: BATCH_SIZE) do |batch| .each_batch(of: BATCH_SIZE) do |batch|
batch.old.update_all(expire_at: old_artifact_expiry_date) batch.old.update_all(expire_at: old_artifact_expiry_date)
batch.recent.update_all(expire_at: recent_artifact_expiry_date) batch.recent.update_all(expire_at: recent_artifact_expiry_date)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment