Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/users/migrate_records_to_ghost_user_in_batches_service.rb')
-rw-r--r--app/services/users/migrate_records_to_ghost_user_in_batches_service.rb25
1 files changed, 19 insertions, 6 deletions
diff --git a/app/services/users/migrate_records_to_ghost_user_in_batches_service.rb b/app/services/users/migrate_records_to_ghost_user_in_batches_service.rb
index 7c4a5698ea9..d294312cc30 100644
--- a/app/services/users/migrate_records_to_ghost_user_in_batches_service.rb
+++ b/app/services/users/migrate_records_to_ghost_user_in_batches_service.rb
@@ -2,25 +2,38 @@
module Users
class MigrateRecordsToGhostUserInBatchesService
+ LIMIT_SIZE = 1000
+
def initialize
@execution_tracker = Gitlab::Utils::ExecutionTracker.new
end
def execute
- Users::GhostUserMigration.find_each do |user_to_migrate|
+ ghost_user_migrations.each do |job|
break if execution_tracker.over_limit?
- service = Users::MigrateRecordsToGhostUserService.new(user_to_migrate.user,
- user_to_migrate.initiator_user,
+ service = Users::MigrateRecordsToGhostUserService.new(job.user,
+ job.initiator_user,
execution_tracker)
- service.execute(hard_delete: user_to_migrate.hard_delete)
+ service.execute(hard_delete: job.hard_delete)
+ rescue Gitlab::Utils::ExecutionTracker::ExecutionTimeOutError
+ # no-op
+ rescue StandardError => e
+ ::Gitlab::ErrorTracking.track_exception(e)
+ reschedule(job)
end
- rescue Gitlab::Utils::ExecutionTracker::ExecutionTimeOutError
- # no-op
end
private
attr_reader :execution_tracker
+
+ def ghost_user_migrations
+ Users::GhostUserMigration.consume_order.limit(LIMIT_SIZE)
+ end
+
+ def reschedule(job)
+ job.update(consume_after: 30.minutes.from_now)
+ end
end
end