blob: cf547c0e6b5162e5568dc2bd6d15f5326e75d562 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# frozen_string_literal: true
module BatchedGitRefUpdates
class CleanupSchedulerService
include Gitlab::ExclusiveLeaseHelpers
MAX_PROJECTS = 10_000
BATCH_SIZE = 100
LOCK_TIMEOUT = 10.minutes
def execute
total_projects = 0
in_lock(self.class.name, retries: 0, ttl: LOCK_TIMEOUT) do
Deletion.status_pending.distinct_each_batch(column: :project_id, of: BATCH_SIZE) do |deletions|
ProjectCleanupWorker.bulk_perform_async_with_contexts(
deletions,
arguments_proc: ->(deletion) { deletion.project_id },
context_proc: ->(_) { {} } # No project context because loading the project is wasteful
)
total_projects += deletions.count
break if total_projects >= MAX_PROJECTS
end
end
{ total_projects: total_projects }
end
end
end
|