summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-02-28 21:11:38 +0900
committerShinya Maeda <shinya@gitlab.com>2018-03-06 17:02:47 +0900
commit99b0542cb0be67fd9af2de74133efb8911519947 (patch)
treec2dd9e3649c5d4ff80d01f0955cb24565c81676f
parent22a7f1f9ad4504c51657b1957b01a7646eee78cd (diff)
downloadgitlab-ce-99b0542cb0be67fd9af2de74133efb8911519947.tar.gz
Add post migration for checksum calculation
-rw-r--r--app/workers/all_queues.yml2
-rw-r--r--app/workers/update_artifact_checksum_worker.rb11
-rw-r--r--db/post_migrate/20180228121020_update_checksum_for_ci_job_artifacts.rb25
3 files changed, 38 insertions, 0 deletions
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml
index 328db19be29..e47a8ca3985 100644
--- a/app/workers/all_queues.yml
+++ b/app/workers/all_queues.yml
@@ -104,3 +104,5 @@
- update_user_activity
- upload_checksum
- web_hook
+
+- object_storage:update_artifact_checksum_worker \ No newline at end of file
diff --git a/app/workers/update_artifact_checksum_worker.rb b/app/workers/update_artifact_checksum_worker.rb
new file mode 100644
index 00000000000..a83fad04b95
--- /dev/null
+++ b/app/workers/update_artifact_checksum_worker.rb
@@ -0,0 +1,11 @@
+class UpdateArtifactChecksumWorker
+ include ApplicationWorker
+ include ObjectStorageQueue
+
+ def perform(job_artifact_id)
+ Ci::JobArtifact.find_by(id: job_artifact_id).try do |job_artifact|
+ job_artifact.set_checksum
+ job_artifact.save!
+ end
+ end
+end
diff --git a/db/post_migrate/20180228121020_update_checksum_for_ci_job_artifacts.rb b/db/post_migrate/20180228121020_update_checksum_for_ci_job_artifacts.rb
new file mode 100644
index 00000000000..bf69c647b4d
--- /dev/null
+++ b/db/post_migrate/20180228121020_update_checksum_for_ci_job_artifacts.rb
@@ -0,0 +1,25 @@
+class UpdateChecksumForCiJobArtifacts < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ BATCH_SIZE = 2500
+
+ class JobArtifact < ActiveRecord::Base
+ include EachBatch
+ self.table_name = 'ci_job_artifacts'
+ end
+
+ def up
+ UpdateChecksumForCiJobArtifacts::JobArtifact
+ .where('checksum IS NULL')
+ .each_batch(of: BATCH_SIZE) do |relation|
+ ids = relation.pluck(:id).map { |id| [id] }
+
+ UpdateArtifactChecksumWorker.bulk_perform_async(ids)
+ end
+ end
+
+ def down
+ # no-op
+ end
+end