summaryrefslogtreecommitdiff
path: root/lib/gitlab
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-06-05 12:35:21 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2018-06-05 12:35:21 +0000
commit40dc82f8628f597548a39a31bddf2aaccc7fc38c (patch)
tree2baf01a5a796d4eff948546178fe3608006cb86c /lib/gitlab
parent049519e718d84f06af1510d2236a0819372fea56 (diff)
parent8f1f73d4e3ca82e3d449e478606f133d19ead7b1 (diff)
downloadgitlab-ce-40dc82f8628f597548a39a31bddf2aaccc7fc38c.tar.gz
Merge branch 'add-background-migrations-for-not-archived-traces' into 'master'
Add background migrations to archive legacy job traces Closes #46642 See merge request gitlab-org/gitlab-ce!19194
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/background_migration/archive_legacy_traces.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/archive_legacy_traces.rb b/lib/gitlab/background_migration/archive_legacy_traces.rb
new file mode 100644
index 00000000000..5a4e5b2c471
--- /dev/null
+++ b/lib/gitlab/background_migration/archive_legacy_traces.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+# rubocop:disable Metrics/AbcSize
+# rubocop:disable Style/Documentation
+
+module Gitlab
+ module BackgroundMigration
+ class ArchiveLegacyTraces
+ def perform(start_id, stop_id)
+ # This background migration directly refers to ::Ci::Build model which is defined in application code.
+ # In general, migration code should be isolated as much as possible in order to be idempotent.
+ # 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
+ ::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
+ end
+ end
+ end
+ end
+end