Commit 5df6de2e authored by Peter Leitzen's avatar Peter Leitzen

Enable cop CodeReuse/Worker

Also, disable current offenses via:
rubocop --auto-correct --disable-uncorrectable --only CodeReuse/Worker

The MR https://gitlab.com/gitlab-org/gitlab/-/merge_requests/7229 missed
to actually enable the cop due to a missing `require` statement.

This was discovered during:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24662
parent 57acb8eb
...@@ -66,7 +66,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -66,7 +66,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
end end
def clear_repository_check_states def clear_repository_check_states
RepositoryCheck::ClearWorker.perform_async RepositoryCheck::ClearWorker.perform_async # rubocop:disable CodeReuse/Worker
redirect_to( redirect_to(
general_admin_application_settings_path, general_admin_application_settings_path,
...@@ -83,7 +83,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -83,7 +83,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
# Specs are in spec/requests/self_monitoring_project_spec.rb # Specs are in spec/requests/self_monitoring_project_spec.rb
def create_self_monitoring_project def create_self_monitoring_project
job_id = SelfMonitoringProjectCreateWorker.perform_async job_id = SelfMonitoringProjectCreateWorker.perform_async # rubocop:disable CodeReuse/Worker
render status: :accepted, json: { render status: :accepted, json: {
job_id: job_id, job_id: job_id,
...@@ -102,7 +102,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -102,7 +102,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
} }
end end
if SelfMonitoringProjectCreateWorker.in_progress?(job_id) if SelfMonitoringProjectCreateWorker.in_progress?(job_id) # rubocop:disable CodeReuse/Worker
::Gitlab::PollingInterval.set_header(response, interval: 3_000) ::Gitlab::PollingInterval.set_header(response, interval: 3_000)
return render status: :accepted, json: { return render status: :accepted, json: {
...@@ -122,7 +122,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -122,7 +122,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
# Specs are in spec/requests/self_monitoring_project_spec.rb # Specs are in spec/requests/self_monitoring_project_spec.rb
def delete_self_monitoring_project def delete_self_monitoring_project
job_id = SelfMonitoringProjectDeleteWorker.perform_async job_id = SelfMonitoringProjectDeleteWorker.perform_async # rubocop:disable CodeReuse/Worker
render status: :accepted, json: { render status: :accepted, json: {
job_id: job_id, job_id: job_id,
...@@ -141,7 +141,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -141,7 +141,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
} }
end end
if SelfMonitoringProjectDeleteWorker.in_progress?(job_id) if SelfMonitoringProjectDeleteWorker.in_progress?(job_id) # rubocop:disable CodeReuse/Worker
::Gitlab::PollingInterval.set_header(response, interval: 3_000) ::Gitlab::PollingInterval.set_header(response, interval: 3_000)
return render status: :accepted, json: { return render status: :accepted, json: {
......
...@@ -55,7 +55,7 @@ class Admin::ProjectsController < Admin::ApplicationController ...@@ -55,7 +55,7 @@ class Admin::ProjectsController < Admin::ApplicationController
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def repository_check def repository_check
RepositoryCheck::SingleRepositoryWorker.perform_async(@project.id) RepositoryCheck::SingleRepositoryWorker.perform_async(@project.id) # rubocop:disable CodeReuse/Worker
redirect_to( redirect_to(
admin_project_path(@project), admin_project_path(@project),
......
...@@ -19,7 +19,7 @@ class Admin::ServicesController < Admin::ApplicationController ...@@ -19,7 +19,7 @@ class Admin::ServicesController < Admin::ApplicationController
def update def update
if service.update(service_params[:service]) if service.update(service_params[:service])
PropagateServiceTemplateWorker.perform_async(service.id) if service.active? PropagateServiceTemplateWorker.perform_async(service.id) if service.active? # rubocop:disable CodeReuse/Worker
redirect_to admin_application_settings_services_path, redirect_to admin_application_settings_services_path,
notice: 'Application settings saved successfully' notice: 'Application settings saved successfully'
......
...@@ -188,7 +188,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -188,7 +188,7 @@ class Projects::IssuesController < Projects::ApplicationController
def import_csv def import_csv
if uploader = UploadService.new(project, params[:file]).execute if uploader = UploadService.new(project, params[:file]).execute
ImportIssuesCsvWorker.perform_async(current_user.id, project.id, uploader.upload.id) ImportIssuesCsvWorker.perform_async(current_user.id, project.id, uploader.upload.id) # rubocop:disable CodeReuse/Worker
flash[:notice] = _("Your issues are being imported. Once finished, you'll get a confirmation email.") flash[:notice] = _("Your issues are being imported. Once finished, you'll get a confirmation email.")
else else
......
...@@ -47,7 +47,7 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController ...@@ -47,7 +47,7 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
end end
def play def play
job_id = RunPipelineScheduleWorker.perform_async(schedule.id, current_user.id) job_id = RunPipelineScheduleWorker.perform_async(schedule.id, current_user.id) # rubocop:disable CodeReuse/Worker
if job_id if job_id
pipelines_link_start = "<a href=\"#{project_pipelines_path(@project)}\">" pipelines_link_start = "<a href=\"#{project_pipelines_path(@project)}\">"
......
...@@ -32,7 +32,7 @@ module Projects ...@@ -32,7 +32,7 @@ module Projects
end end
def destroy def destroy
DeleteContainerRepositoryWorker.perform_async(current_user.id, image.id) DeleteContainerRepositoryWorker.perform_async(current_user.id, image.id) # rubocop:disable CodeReuse/Worker
track_event(:delete_repository) track_event(:delete_repository)
respond_to do |format| respond_to do |format|
......
...@@ -69,7 +69,9 @@ module Projects ...@@ -69,7 +69,9 @@ module Projects
return return
end end
# rubocop:disable CodeReuse/Worker
CreatePipelineWorker.perform_async(project.id, current_user.id, project.default_branch, :web, ignore_skip_ci: true, save_on_errors: false) CreatePipelineWorker.perform_async(project.id, current_user.id, project.default_branch, :web, ignore_skip_ci: true, save_on_errors: false)
# rubocop:enable CodeReuse/Worker
pipelines_link_start = '<a href="%{url}">'.html_safe % { url: project_pipelines_path(@project) } pipelines_link_start = '<a href="%{url}">'.html_safe % { url: project_pipelines_path(@project) }
flash[:toast] = _("A new Auto DevOps pipeline has been created, go to %{pipelines_link_start}Pipelines page%{pipelines_link_end} for details") % { pipelines_link_start: pipelines_link_start, pipelines_link_end: "</a>".html_safe } flash[:toast] = _("A new Auto DevOps pipeline has been created, go to %{pipelines_link_start}Pipelines page%{pipelines_link_end} for details") % { pipelines_link_start: pipelines_link_start, pipelines_link_end: "</a>".html_safe }
......
...@@ -25,7 +25,7 @@ module Projects ...@@ -25,7 +25,7 @@ module Projects
result = Projects::UpdateService.new(project, current_user, cleanup_params).execute result = Projects::UpdateService.new(project, current_user, cleanup_params).execute
if result[:status] == :success if result[:status] == :success
RepositoryCleanupWorker.perform_async(project.id, current_user.id) RepositoryCleanupWorker.perform_async(project.id, current_user.id) # rubocop:disable CodeReuse/Worker
flash[:notice] = _('Repository cleanup has started. You will receive an email once the cleanup operation is complete.') flash[:notice] = _('Repository cleanup has started. You will receive an email once the cleanup operation is complete.')
else else
flash[:alert] = _('Failed to upload object map file') flash[:alert] = _('Failed to upload object map file')
......
...@@ -80,7 +80,7 @@ module Repositories ...@@ -80,7 +80,7 @@ module Repositories
return unless repo_type.project? return unless repo_type.project?
return unless project&.daily_statistics_enabled? return unless project&.daily_statistics_enabled?
ProjectDailyStatisticsWorker.perform_async(project.id) ProjectDailyStatisticsWorker.perform_async(project.id) # rubocop:disable CodeReuse/Worker
end end
def access def access
......
...@@ -5,7 +5,7 @@ class Admin::EmailsController < Admin::ApplicationController ...@@ -5,7 +5,7 @@ class Admin::EmailsController < Admin::ApplicationController
end end
def create def create
AdminEmailsWorker.perform_async(params[:recipients], params[:subject], params[:body]) AdminEmailsWorker.perform_async(params[:recipients], params[:subject], params[:body]) # rubocop:disable CodeReuse/Worker
redirect_to admin_email_path, notice: 'Email sent' redirect_to admin_email_path, notice: 'Email sent'
end end
end end
...@@ -58,14 +58,14 @@ class Admin::Geo::ProjectsController < Admin::Geo::ApplicationController ...@@ -58,14 +58,14 @@ class Admin::Geo::ProjectsController < Admin::Geo::ApplicationController
end end
def reverify_all def reverify_all
Geo::Batch::ProjectRegistrySchedulerWorker.perform_async(:reverify_repositories) Geo::Batch::ProjectRegistrySchedulerWorker.perform_async(:reverify_repositories) # rubocop:disable CodeReuse/Worker
flash[:toast] = s_('Geo|All projects are being scheduled for re-verify') flash[:toast] = s_('Geo|All projects are being scheduled for re-verify')
redirect_back_or_default(default: admin_geo_projects_path) redirect_back_or_default(default: admin_geo_projects_path)
end end
def resync_all def resync_all
Geo::Batch::ProjectRegistrySchedulerWorker.perform_async(:resync_repositories) Geo::Batch::ProjectRegistrySchedulerWorker.perform_async(:resync_repositories) # rubocop:disable CodeReuse/Worker
flash[:toast] = s_('Geo|All projects are being scheduled for re-sync') flash[:toast] = s_('Geo|All projects are being scheduled for re-sync')
redirect_back_or_default(default: admin_geo_projects_path) redirect_back_or_default(default: admin_geo_projects_path)
......
...@@ -12,7 +12,7 @@ class Groups::LdapsController < Groups::ApplicationController ...@@ -12,7 +12,7 @@ class Groups::LdapsController < Groups::ApplicationController
# likely the group will never transition out of its current state, # likely the group will never transition out of its current state,
# so we should tell the group owner. # so we should tell the group owner.
if @group.pending_ldap_sync if @group.pending_ldap_sync
LdapGroupSyncWorker.perform_async(@group.id) LdapGroupSyncWorker.perform_async(@group.id) # rubocop:disable CodeReuse/Worker
message = 'The group sync has been scheduled' message = 'The group sync has been scheduled'
elsif @group.valid? elsif @group.valid?
message = 'The group sync is already scheduled' message = 'The group sync is already scheduled'
......
...@@ -41,7 +41,7 @@ class ElasticsearchIndexedNamespace < ApplicationRecord ...@@ -41,7 +41,7 @@ class ElasticsearchIndexedNamespace < ApplicationRecord
jobs = batch_ids.map { |id| [id, :index] } jobs = batch_ids.map { |id| [id, :index] }
ElasticNamespaceIndexerWorker.bulk_perform_async(jobs) # rubocop:disable Scalability/BulkPerformWithContext ElasticNamespaceIndexerWorker.bulk_perform_async(jobs) # rubocop:disable Scalability/BulkPerformWithContext, CodeReuse/Worker
end end
end end
...@@ -58,7 +58,7 @@ class ElasticsearchIndexedNamespace < ApplicationRecord ...@@ -58,7 +58,7 @@ class ElasticsearchIndexedNamespace < ApplicationRecord
jobs = batch_ids.map { |id| [id, :delete] } jobs = batch_ids.map { |id| [id, :delete] }
ElasticNamespaceIndexerWorker.bulk_perform_async(jobs) # rubocop:disable Scalability/BulkPerformWithContext ElasticNamespaceIndexerWorker.bulk_perform_async(jobs) # rubocop:disable Scalability/BulkPerformWithContext, CodeReuse/Worker
end end
end end
......
...@@ -127,7 +127,7 @@ class GeoNodeStatus < ApplicationRecord ...@@ -127,7 +127,7 @@ class GeoNodeStatus < ApplicationRecord
end end
def self.spawn_worker def self.spawn_worker
::Geo::MetricsUpdateWorker.perform_async ::Geo::MetricsUpdateWorker.perform_async # rubocop:disable CodeReuse/Worker
end end
def self.cache_key def self.cache_key
......
...@@ -21,7 +21,7 @@ module API ...@@ -21,7 +21,7 @@ module API
requires :plan, type: String, values: Plan::ALL_HOSTED_PLANS requires :plan, type: String, values: Plan::ALL_HOSTED_PLANS
end end
put 'rollout' do put 'rollout' do
ElasticNamespaceRolloutWorker.perform_async(params[:plan], params[:percentage], ElasticNamespaceRolloutWorker::ROLLOUT) ElasticNamespaceRolloutWorker.perform_async(params[:plan], params[:percentage], ElasticNamespaceRolloutWorker::ROLLOUT) # rubocop:disable CodeReuse/Worker
end end
desc 'Rollback namespaces to be indexed down to n%' do desc 'Rollback namespaces to be indexed down to n%' do
...@@ -38,7 +38,7 @@ module API ...@@ -38,7 +38,7 @@ module API
requires :plan, type: String, values: Plan::ALL_HOSTED_PLANS requires :plan, type: String, values: Plan::ALL_HOSTED_PLANS
end end
put 'rollback' do put 'rollback' do
ElasticNamespaceRolloutWorker.perform_async(params[:plan], params[:percentage], ElasticNamespaceRolloutWorker::ROLLBACK) ElasticNamespaceRolloutWorker.perform_async(params[:plan], params[:percentage], ElasticNamespaceRolloutWorker::ROLLBACK) # rubocop:disable CodeReuse/Worker
end end
end end
end end
......
...@@ -129,7 +129,7 @@ module API ...@@ -129,7 +129,7 @@ module API
track_event('push_package') track_event('push_package')
::Packages::Nuget::ExtractionWorker.perform_async(package_file.id) ::Packages::Nuget::ExtractionWorker.perform_async(package_file.id) # rubocop:disable CodeReuse/Worker
created! created!
rescue ObjectStorage::RemoteStoreError => e rescue ObjectStorage::RemoteStoreError => e
......
...@@ -27,7 +27,7 @@ module API ...@@ -27,7 +27,7 @@ module API
detail 'This feature was introduced in GitLab 12.5.' detail 'This feature was introduced in GitLab 12.5.'
end end
post ':id/export' do post ':id/export' do
GroupExportWorker.perform_async(current_user.id, user_group.id, params) GroupExportWorker.perform_async(current_user.id, user_group.id, params) # rubocop:disable CodeReuse/Worker
accepted! accepted!
end end
......
...@@ -65,7 +65,7 @@ module API ...@@ -65,7 +65,7 @@ module API
group = ::Groups::CreateService.new(current_user, group_params).execute group = ::Groups::CreateService.new(current_user, group_params).execute
if group.persisted? if group.persisted?
GroupImportWorker.perform_async(current_user.id, group.id) GroupImportWorker.perform_async(current_user.id, group.id) # rubocop:disable CodeReuse/Worker
accepted! accepted!
else else
......
...@@ -120,7 +120,7 @@ module API ...@@ -120,7 +120,7 @@ module API
post ':id/pipeline_schedules/:pipeline_schedule_id/play' do post ':id/pipeline_schedules/:pipeline_schedule_id/play' do
authorize! :play_pipeline_schedule, pipeline_schedule authorize! :play_pipeline_schedule, pipeline_schedule
job_id = RunPipelineScheduleWorker job_id = RunPipelineScheduleWorker # rubocop:disable CodeReuse/Worker
.perform_async(pipeline_schedule.id, current_user.id) .perform_async(pipeline_schedule.id, current_user.id)
if job_id if job_id
......
...@@ -41,7 +41,7 @@ module API ...@@ -41,7 +41,7 @@ module API
delete ':id/registry/repositories/:repository_id', requirements: REPOSITORY_ENDPOINT_REQUIREMENTS do delete ':id/registry/repositories/:repository_id', requirements: REPOSITORY_ENDPOINT_REQUIREMENTS do
authorize_admin_container_image! authorize_admin_container_image!
DeleteContainerRepositoryWorker.perform_async(current_user.id, repository.id) DeleteContainerRepositoryWorker.perform_async(current_user.id, repository.id) # rubocop:disable CodeReuse/Worker
track_event('delete_repository') track_event('delete_repository')
status :accepted status :accepted
...@@ -79,8 +79,10 @@ module API ...@@ -79,8 +79,10 @@ module API
message = 'This request has already been made. You can run this at most once an hour for a given container repository' message = 'This request has already been made. You can run this at most once an hour for a given container repository'
render_api_error!(message, 400) unless obtain_new_cleanup_container_lease render_api_error!(message, 400) unless obtain_new_cleanup_container_lease
# rubocop:disable CodeReuse/Worker
CleanupContainerRepositoryWorker.perform_async(current_user.id, repository.id, CleanupContainerRepositoryWorker.perform_async(current_user.id, repository.id,
declared_params.except(:repository_id).merge(container_expiration_policy: false)) declared_params.except(:repository_id).merge(container_expiration_policy: false))
# rubocop:enable CodeReuse/Worker
track_event('delete_tag_bulk') track_event('delete_tag_bulk')
......
...@@ -170,9 +170,9 @@ module API ...@@ -170,9 +170,9 @@ module API
return if release.historical_release? return if release.historical_release?
if release.upcoming_release? if release.upcoming_release?
CreateEvidenceWorker.perform_at(release.released_at, release.id) CreateEvidenceWorker.perform_at(release.released_at, release.id) # rubocop:disable CodeReuse/Worker
else else
CreateEvidenceWorker.perform_async(release.id) CreateEvidenceWorker.perform_async(release.id) # rubocop:disable CodeReuse/Worker
end end
end end
end end
......
...@@ -55,6 +55,7 @@ require_relative 'cop/code_reuse/service_class' ...@@ -55,6 +55,7 @@ require_relative 'cop/code_reuse/service_class'
require_relative 'cop/code_reuse/presenter' require_relative 'cop/code_reuse/presenter'
require_relative 'cop/code_reuse/serializer' require_relative 'cop/code_reuse/serializer'
require_relative 'cop/code_reuse/active_record' require_relative 'cop/code_reuse/active_record'
require_relative 'cop/code_reuse/worker'
require_relative 'cop/group_public_or_visible_to_user' require_relative 'cop/group_public_or_visible_to_user'
require_relative 'cop/inject_enterprise_edition_module' require_relative 'cop/inject_enterprise_edition_module'
require_relative 'cop/graphql/authorize_types' require_relative 'cop/graphql/authorize_types'
......
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