2018-05-29 04:06:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
# rubocop:disable Style/Documentation
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module BackgroundMigration
|
|
|
|
class ArchiveLegacyTraces
|
|
|
|
def perform(start_id, stop_id)
|
2018-06-03 02:13:36 -04:00
|
|
|
# This background migration directly refers to ::Ci::Build model which is defined in application code.
|
2018-06-03 01:21:50 -04:00
|
|
|
# In general, migration code should be isolated as much as possible in order to be idempotent.
|
2018-06-03 02:13:36 -04:00
|
|
|
# However, `archive!` method is too complicated to be replicated by coping its subsequent code.
|
|
|
|
# So we chose a way to use ::Ci::Build directly and we don't change the `archive!` method until 11.1
|
2018-06-03 01:21:50 -04:00
|
|
|
::Ci::Build.finished.without_archived_trace
|
|
|
|
.where(id: start_id..stop_id).find_each do |build|
|
|
|
|
begin
|
|
|
|
build.trace.archive!
|
|
|
|
rescue => e
|
|
|
|
Rails.logger.error "Failed to archive live trace. id: #{build.id} message: #{e.message}"
|
|
|
|
end
|
2018-05-29 04:06:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|