summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-01-24 11:52:09 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2017-01-24 11:52:09 +0000
commit70a717042f99e19e53f694f4aaee6b497d11bb74 (patch)
treea42df71fce83c312b3cad4761240aa724d521695
parent58786a7a41b36e84dda91cdca04671b6e613974d (diff)
parente4d402427c10c48651e3c306e7e3aabf094d1443 (diff)
downloadgitlab-ce-70a717042f99e19e53f694f4aaee6b497d11bb74.tar.gz
Merge branch 'zj-requeue-pending-delete' into 'master'
Requeue projects pending deletion See merge request !8438
-rw-r--r--changelogs/unreleased/zj-requeue-pending-delete.yml4
-rw-r--r--db/post_migrate/20170104150317_requeue_pending_delete_projects.rb49
2 files changed, 53 insertions, 0 deletions
diff --git a/changelogs/unreleased/zj-requeue-pending-delete.yml b/changelogs/unreleased/zj-requeue-pending-delete.yml
new file mode 100644
index 00000000000..464c5948f8c
--- /dev/null
+++ b/changelogs/unreleased/zj-requeue-pending-delete.yml
@@ -0,0 +1,4 @@
+---
+title: Requeue pending deletion projects
+merge_request:
+author:
diff --git a/db/post_migrate/20170104150317_requeue_pending_delete_projects.rb b/db/post_migrate/20170104150317_requeue_pending_delete_projects.rb
new file mode 100644
index 00000000000..f399950bd5e
--- /dev/null
+++ b/db/post_migrate/20170104150317_requeue_pending_delete_projects.rb
@@ -0,0 +1,49 @@
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class RequeuePendingDeleteProjects < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ admin = User.find_by(admin: true)
+ return unless admin
+
+ @offset = 0
+
+ loop do
+ ids = pending_delete_batch
+
+ break if ids.rows.count.zero?
+
+ args = ids.map { |id| [id['id'], admin.id, {}] }
+
+ Sidekiq::Client.push_bulk('class' => "ProjectDestroyWorker", 'args' => args)
+
+ @offset += 1
+ end
+ end
+
+ def down
+ # noop
+ end
+
+ private
+
+ def pending_delete_batch
+ connection.exec_query(find_batch)
+ end
+
+ BATCH_SIZE = 5000
+
+ def find_batch
+ projects = Arel::Table.new(:projects)
+ projects.project(projects[:id]).
+ where(projects[:pending_delete].eq(true)).
+ where(projects[:namespace_id].not_eq(nil)).
+ skip(@offset * BATCH_SIZE).
+ take(BATCH_SIZE).
+ to_sql
+ end
+end