Class: Gitlab::BackgroundMigration::RemoveBackfilledJobArtifactsExpireAt

Inherits:
BatchedMigrationJob show all
Defined in:
lib/gitlab/background_migration/remove_backfilled_job_artifacts_expire_at.rb

Overview

This detects and fixes job artifacts that have ‘expire_at` wrongly backfilled by the migration gitlab.com/gitlab-org/gitlab/-/merge_requests/47723. These job artifacts will not be deleted and will have their `expire_at` removed.

Constant Summary collapse

EXPIRES_ON_21_22_23_AT_MIDNIGHT_IN_TIMEZONE =

The migration would have backfilled ‘expire_at` to midnight on the 22nd of the month of the local timezone, storing it as UTC time in the database.

If the timezone setting has changed since the migration, the ‘expire_at` stored in the database could have changed to a different local time other than midnight. For example:

  • changing timezone from UTC+02:00 to UTC+02:30 would change the ‘expire_at` in local time 00:00:00 to 00:30:00.

  • changing timezone from UTC+00:00 to UTC-01:00 would change the ‘expire_at` in local time 00:00:00 to 23:00:00 on the previous day (21st).

Therefore job artifacts that have ‘expire_at` exactly on the 00, 30 or 45 minute mark on the dates 21, 22, 23 of the month will not be deleted. en.wikipedia.org/wiki/List_of_UTC_time_offsets

<<~SQL
  EXTRACT(day FROM timezone('UTC', expire_at)) IN (21, 22, 23)
  AND EXTRACT(minute FROM timezone('UTC', expire_at)) IN (0, 30, 45)
  AND EXTRACT(second FROM timezone('UTC', expire_at)) = 0
SQL

Constants inherited from BatchedMigrationJob

BatchedMigrationJob::DEFAULT_FEATURE_CATEGORY

Constants included from Database::DynamicModelHelpers

Database::DynamicModelHelpers::BATCH_SIZE

Instance Method Summary collapse

Methods inherited from BatchedMigrationJob

#batch_metrics, feature_category, #filter_batch, generic_instance, #initialize, job_arguments, job_arguments_count, operation_name, scope_to

Methods included from Database::DynamicModelHelpers

#define_batchable_model, #each_batch, #each_batch_range

Constructor Details

This class inherits a constructor from Gitlab::BackgroundMigration::BatchedMigrationJob

Instance Method Details

#performObject



37
38
39
40
41
# File 'lib/gitlab/background_migration/remove_backfilled_job_artifacts_expire_at.rb', line 37

def perform
  each_sub_batch do |sub_batch|
    sub_batch.update_all(expire_at: nil)
  end
end