Commit 08807f2a authored by Bob Van Landuyt's avatar Bob Van Landuyt Committed by Imre Farkas

Add context to the AdjournedGroupsDeletionWorker

Jobs that could be scheduled from this worker:

- WebHookWorker
- GitlabShellWorker
- DeleteStoredFilesWorker
- DeleteStoredFilesWorker
- GroupDestroyWorker
- ProjectCacheWorker
- PagesWorker
- MailScheduler::NotificationServiceWorker
- ObjectPool::DestroyWorker
parent c8ace7cd
......@@ -59,7 +59,7 @@ module EE
validate :custom_project_templates_group_allowed, if: :custom_project_templates_group_id_changed?
scope :aimed_for_deletion, -> (date) { joins(:deletion_schedule).where('group_deletion_schedules.marked_for_deletion_on <= ?', date) }
scope :with_deletion_schedule, -> { preload(:deletion_schedule) }
scope :with_deletion_schedule, -> { preload(deletion_schedule: :deleting_user) }
scope :where_group_links_with_provider, ->(provider) do
joins(:ldap_group_links).where(ldap_group_links: { provider: provider })
......
......@@ -143,6 +143,7 @@ module EE
scope :with_repos_templates, -> { where(namespace_id: ::Gitlab::CurrentSettings.current_application_settings.custom_project_templates_group_id) }
scope :with_groups_level_repos_templates, -> { joins("INNER JOIN namespaces ON projects.namespace_id = namespaces.custom_project_templates_group_id") }
scope :with_designs, -> { where(id: DesignManagement::Design.select(:project_id)) }
scope :with_deleting_user, -> { includes(:deleting_user) }
delegate :shared_runners_minutes, :shared_runners_seconds, :shared_runners_seconds_last_reset,
to: :statistics, allow_nil: true
......
......@@ -2,7 +2,7 @@
class AdjournedGroupDeletionWorker
include ApplicationWorker
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
include CronjobQueue
INTERVAL = 5.minutes.to_i
......@@ -11,14 +11,16 @@ class AdjournedGroupDeletionWorker
def perform
deletion_cutoff = Gitlab::CurrentSettings.deletion_adjourned_period.days.ago.to_date
Group.aimed_for_deletion(deletion_cutoff)
Group.with_route.aimed_for_deletion(deletion_cutoff)
.with_deletion_schedule
.find_each(batch_size: 100) # rubocop: disable CodeReuse/ActiveRecord
.with_index do |group, index|
deletion_schedule = group.deletion_schedule
delay = index * INTERVAL
with_context(namespace: group, user: deletion_schedule.deleting_user) do
GroupDestroyWorker.perform_in(delay, group.id, deletion_schedule.user_id)
end
end
end
end
......@@ -2,7 +2,7 @@
class AdjournedProjectsDeletionCronWorker
include ApplicationWorker
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
include CronjobQueue
INTERVAL = 5.minutes.to_i
......@@ -11,10 +11,12 @@ class AdjournedProjectsDeletionCronWorker
def perform
deletion_cutoff = Gitlab::CurrentSettings.deletion_adjourned_period.days.ago.to_date
Project.aimed_for_deletion(deletion_cutoff).find_each(batch_size: 100).with_index do |project, index| # rubocop: disable CodeReuse/ActiveRecord
Project.with_route.with_deleting_user.aimed_for_deletion(deletion_cutoff).find_each(batch_size: 100).with_index do |project, index| # rubocop: disable CodeReuse/ActiveRecord
delay = index * INTERVAL
with_context(project: project, user: project.deleting_user) do
AdjournedProjectDeletionWorker.perform_in(delay, project.id)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment