Commit 7b79ae26 authored by Imre Farkas's avatar Imre Farkas

Merge branch 'bvl-add-context-to-adjourned-workers' into 'master'

Add context to some deletion workers

See merge request gitlab-org/gitlab!24703
parents 54a12b7e 08807f2a
...@@ -59,7 +59,7 @@ module EE ...@@ -59,7 +59,7 @@ module EE
validate :custom_project_templates_group_allowed, if: :custom_project_templates_group_id_changed? 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 :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 scope :where_group_links_with_provider, ->(provider) do
joins(:ldap_group_links).where(ldap_group_links: { provider: provider }) joins(:ldap_group_links).where(ldap_group_links: { provider: provider })
......
...@@ -143,6 +143,7 @@ module EE ...@@ -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_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_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_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, delegate :shared_runners_minutes, :shared_runners_seconds, :shared_runners_seconds_last_reset,
to: :statistics, allow_nil: true to: :statistics, allow_nil: true
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
class AdjournedGroupDeletionWorker class AdjournedGroupDeletionWorker
include ApplicationWorker include ApplicationWorker
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext include CronjobQueue
INTERVAL = 5.minutes.to_i INTERVAL = 5.minutes.to_i
...@@ -11,14 +11,16 @@ class AdjournedGroupDeletionWorker ...@@ -11,14 +11,16 @@ class AdjournedGroupDeletionWorker
def perform def perform
deletion_cutoff = Gitlab::CurrentSettings.deletion_adjourned_period.days.ago.to_date 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 .with_deletion_schedule
.find_each(batch_size: 100) # rubocop: disable CodeReuse/ActiveRecord .find_each(batch_size: 100) # rubocop: disable CodeReuse/ActiveRecord
.with_index do |group, index| .with_index do |group, index|
deletion_schedule = group.deletion_schedule deletion_schedule = group.deletion_schedule
delay = index * INTERVAL delay = index * INTERVAL
GroupDestroyWorker.perform_in(delay, group.id, deletion_schedule.user_id) with_context(namespace: group, user: deletion_schedule.deleting_user) do
GroupDestroyWorker.perform_in(delay, group.id, deletion_schedule.user_id)
end
end end
end end
end end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
class AdjournedProjectsDeletionCronWorker class AdjournedProjectsDeletionCronWorker
include ApplicationWorker include ApplicationWorker
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext include CronjobQueue
INTERVAL = 5.minutes.to_i INTERVAL = 5.minutes.to_i
...@@ -11,10 +11,12 @@ class AdjournedProjectsDeletionCronWorker ...@@ -11,10 +11,12 @@ class AdjournedProjectsDeletionCronWorker
def perform def perform
deletion_cutoff = Gitlab::CurrentSettings.deletion_adjourned_period.days.ago.to_date 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 delay = index * INTERVAL
AdjournedProjectDeletionWorker.perform_in(delay, project.id) with_context(project: project, user: project.deleting_user) do
AdjournedProjectDeletionWorker.perform_in(delay, project.id)
end
end end
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