Commit f9237e2d authored by Thong Kuah's avatar Thong Kuah

Fix CodeReuse/ActiveRecord offenses in workers

Use the allowed find_by_id method instead of find_by(id: 1).
parent fd23cb31
...@@ -25,11 +25,9 @@ class AuthorizedProjectsWorker ...@@ -25,11 +25,9 @@ class AuthorizedProjectsWorker
end end
end end
# rubocop: disable CodeReuse/ActiveRecord
def perform(user_id) def perform(user_id)
user = User.find_by(id: user_id) user = User.find_by_id(user_id)
user&.refresh_authorized_projects(source: self.class.name) user&.refresh_authorized_projects(source: self.class.name)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -14,7 +14,7 @@ class BuildHooksWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -14,7 +14,7 @@ class BuildHooksWorker # rubocop:disable Scalability/IdempotentWorker
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def perform(build_id) def perform(build_id)
Ci::Build.includes({ runner: :tags }) Ci::Build.includes({ runner: :tags })
.find_by(id: build_id) .find_by_id(build_id)
.try(:execute_hooks) .try(:execute_hooks)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -12,11 +12,9 @@ class BuildQueueWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -12,11 +12,9 @@ class BuildQueueWorker # rubocop:disable Scalability/IdempotentWorker
worker_resource_boundary :cpu worker_resource_boundary :cpu
data_consistency :sticky data_consistency :sticky
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id) def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build| Ci::Build.find_by_id(build_id).try do |build|
Ci::UpdateBuildQueueService.new.tick(build) Ci::UpdateBuildQueueService.new.tick(build)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -11,13 +11,11 @@ class BuildSuccessWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -11,13 +11,11 @@ class BuildSuccessWorker # rubocop:disable Scalability/IdempotentWorker
queue_namespace :pipeline_processing queue_namespace :pipeline_processing
urgency :high urgency :high
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id) def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build| Ci::Build.find_by_id(build_id).try do |build|
stop_environment(build) if build.stops_environment? stop_environment(build) if build.stops_environment?
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -16,9 +16,8 @@ class ChatNotificationWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -16,9 +16,8 @@ class ChatNotificationWorker # rubocop:disable Scalability/IdempotentWorker
RESCHEDULE_INTERVAL = 2.seconds RESCHEDULE_INTERVAL = 2.seconds
RESCHEDULE_TIMEOUT = 5.minutes RESCHEDULE_TIMEOUT = 5.minutes
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id, reschedule_count = 0) def perform(build_id, reschedule_count = 0)
Ci::Build.find_by(id: build_id).try do |build| Ci::Build.find_by_id(build_id).try do |build|
send_response(build) send_response(build)
end end
rescue Gitlab::Chat::Output::MissingBuildSectionError rescue Gitlab::Chat::Output::MissingBuildSectionError
...@@ -30,7 +29,6 @@ class ChatNotificationWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -30,7 +29,6 @@ class ChatNotificationWorker # rubocop:disable Scalability/IdempotentWorker
# the job instead of producing an error. # the job instead of producing an error.
self.class.perform_in(RESCHEDULE_INTERVAL, build_id, reschedule_count + 1) self.class.perform_in(RESCHEDULE_INTERVAL, build_id, reschedule_count + 1)
end end
# rubocop: enable CodeReuse/ActiveRecord
def send_response(build) def send_response(build)
Gitlab::Chat::Responder.responder_for(build).try do |responder| Gitlab::Chat::Responder.responder_for(build).try do |responder|
......
...@@ -9,12 +9,10 @@ module Ci ...@@ -9,12 +9,10 @@ module Ci
sidekiq_options retry: 3 sidekiq_options retry: 3
include PipelineBackgroundQueue include PipelineBackgroundQueue
# rubocop: disable CodeReuse/ActiveRecord
def perform(job_id) def perform(job_id)
Ci::Build.without_archived_trace.find_by(id: job_id).try do |job| Ci::Build.without_archived_trace.find_by_id(job_id).try do |job|
Ci::ArchiveTraceService.new.execute(job, worker_name: self.class.name) Ci::ArchiveTraceService.new.execute(job, worker_name: self.class.name)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -16,7 +16,7 @@ module Ci ...@@ -16,7 +16,7 @@ module Ci
ARCHIVE_TRACES_IN = 2.minutes.freeze ARCHIVE_TRACES_IN = 2.minutes.freeze
def perform(build_id) def perform(build_id)
return unless build = Ci::Build.find_by(id: build_id) # rubocop: disable CodeReuse/ActiveRecord return unless build = Ci::Build.find_by_id(build_id)
return unless build.project return unless build.project
return if build.project.pending_delete? return if build.project.pending_delete?
......
...@@ -13,12 +13,10 @@ module Ci ...@@ -13,12 +13,10 @@ module Ci
idempotent! idempotent!
# rubocop: disable CodeReuse/ActiveRecord
def perform(id) def perform(id)
::Ci::BuildTraceChunk.find_by(id: id).try do |chunk| ::Ci::BuildTraceChunk.find_by_id(id).try do |chunk|
chunk.persist_data! chunk.persist_data!
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -26,16 +26,14 @@ class ClusterUpdateAppWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -26,16 +26,14 @@ class ClusterUpdateAppWorker # rubocop:disable Scalability/IdempotentWorker
private private
# rubocop: disable CodeReuse/ActiveRecord
def execute(app_name, app_id, project_id, scheduled_time) def execute(app_name, app_id, project_id, scheduled_time)
project = Project.find_by(id: project_id) project = Project.find_by_id(project_id)
return unless project return unless project
find_application(app_name, app_id) do |app| find_application(app_name, app_id) do |app|
update_prometheus(app, scheduled_time, project) update_prometheus(app, scheduled_time, project)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def update_prometheus(app, scheduled_time, project) def update_prometheus(app, scheduled_time, project)
return unless app.managed_prometheus? return unless app.managed_prometheus?
......
...@@ -8,9 +8,8 @@ module Gitlab ...@@ -8,9 +8,8 @@ module Gitlab
# project_id - The ID of the GitLab project to import the note into. # project_id - The ID of the GitLab project to import the note into.
# hash - A Hash containing the details of the GitHub object to import. # hash - A Hash containing the details of the GitHub object to import.
# notify_key - The Redis key to notify upon completion, if any. # notify_key - The Redis key to notify upon completion, if any.
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id, hash, notify_key = nil) def perform(project_id, hash, notify_key = nil)
project = Project.find_by(id: project_id) project = Project.find_by_id(project_id)
return notify_waiter(notify_key) unless project return notify_waiter(notify_key) unless project
...@@ -25,7 +24,6 @@ module Gitlab ...@@ -25,7 +24,6 @@ module Gitlab
.perform_in(client.rate_limit_resets_in, project.id, hash, notify_key) .perform_in(client.rate_limit_resets_in, project.id, hash, notify_key)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def try_import(*args) def try_import(*args)
import(*args) import(*args)
......
...@@ -33,13 +33,13 @@ module Gitlab ...@@ -33,13 +33,13 @@ module Gitlab
self.class.perform_in(client.rate_limit_resets_in, project.id) self.class.perform_in(client.rate_limit_resets_in, project.id)
end end
# rubocop: disable CodeReuse/ActiveRecord
def find_project(id) def find_project(id)
# If the project has been marked as failed we want to bail out # If the project has been marked as failed we want to bail out
# automatically. # automatically.
Project.joins_import_state.where(import_state: { status: :started }).find_by(id: id) # rubocop: disable CodeReuse/ActiveRecord
Project.joins_import_state.where(import_state: { status: :started }).find_by_id(id)
# rubocop: enable CodeReuse/ActiveRecord
end end
# rubocop: enable CodeReuse/ActiveRecord
def abort_on_failure def abort_on_failure
false false
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
end end
def perform(project_id) def perform(project_id)
project = Project.find_by(id: project_id) # rubocop: disable CodeReuse/ActiveRecord project = Project.find_by_id(project_id)
return unless can_import?(project) return unless can_import?(project)
......
...@@ -10,21 +10,17 @@ module NewIssuable ...@@ -10,21 +10,17 @@ module NewIssuable
user && issuable user && issuable
end end
# rubocop: disable CodeReuse/ActiveRecord
def set_user(user_id) def set_user(user_id)
@user = User.find_by(id: user_id) # rubocop:disable Gitlab/ModuleWithInstanceVariables @user = User.find_by_id(user_id) # rubocop:disable Gitlab/ModuleWithInstanceVariables
log_error(User, user_id) unless @user # rubocop:disable Gitlab/ModuleWithInstanceVariables log_error(User, user_id) unless @user # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def set_issuable(issuable_id) def set_issuable(issuable_id)
@issuable = issuable_class.find_by(id: issuable_id) # rubocop:disable Gitlab/ModuleWithInstanceVariables @issuable = issuable_class.find_by_id(issuable_id) # rubocop:disable Gitlab/ModuleWithInstanceVariables
log_error(issuable_class, issuable_id) unless @issuable # rubocop:disable Gitlab/ModuleWithInstanceVariables log_error(issuable_class, issuable_id) unless @issuable # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
# rubocop: enable CodeReuse/ActiveRecord
def log_error(record_class, record_id) def log_error(record_class, record_id)
Gitlab::AppLogger.error("#{self.class}: couldn't find #{record_class} with ID=#{record_id}, skipping job") Gitlab::AppLogger.error("#{self.class}: couldn't find #{record_class} with ID=#{record_id}, skipping job")
......
...@@ -12,7 +12,6 @@ class CreateCommitSignatureWorker ...@@ -12,7 +12,6 @@ class CreateCommitSignatureWorker
idempotent! idempotent!
loggable_arguments 0 loggable_arguments 0
# rubocop: disable CodeReuse/ActiveRecord
def perform(commit_shas, project_id) def perform(commit_shas, project_id)
# Older versions of Git::BranchPushService may push a single commit ID on # Older versions of Git::BranchPushService may push a single commit ID on
# the stack. We need this to be backwards compatible. # the stack. We need this to be backwards compatible.
...@@ -20,7 +19,7 @@ class CreateCommitSignatureWorker ...@@ -20,7 +19,7 @@ class CreateCommitSignatureWorker
return if commit_shas.empty? return if commit_shas.empty?
project = Project.find_by(id: project_id) project = Project.find_by_id(project_id)
return unless project return unless project
commits = project.commits_by(oids: commit_shas) commits = project.commits_by(oids: commit_shas)
...@@ -44,5 +43,4 @@ class CreateCommitSignatureWorker ...@@ -44,5 +43,4 @@ class CreateCommitSignatureWorker
Gitlab::AppLogger.error("Failed to create signature for commit #{commit.id}. Error: #{e.message}") Gitlab::AppLogger.error("Failed to create signature for commit #{commit.id}. Error: #{e.message}")
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -15,10 +15,9 @@ class DeleteContainerRepositoryWorker # rubocop:disable Scalability/IdempotentWo ...@@ -15,10 +15,9 @@ class DeleteContainerRepositoryWorker # rubocop:disable Scalability/IdempotentWo
attr_reader :container_repository attr_reader :container_repository
# rubocop: disable CodeReuse/ActiveRecord
def perform(current_user_id, container_repository_id) def perform(current_user_id, container_repository_id)
current_user = User.find_by(id: current_user_id) current_user = User.find_by_id(current_user_id)
@container_repository = ContainerRepository.find_by(id: container_repository_id) @container_repository = ContainerRepository.find_by_id(container_repository_id)
project = container_repository&.project project = container_repository&.project
return unless current_user && container_repository && project return unless current_user && container_repository && project
...@@ -29,7 +28,6 @@ class DeleteContainerRepositoryWorker # rubocop:disable Scalability/IdempotentWo ...@@ -29,7 +28,6 @@ class DeleteContainerRepositoryWorker # rubocop:disable Scalability/IdempotentWo
Projects::ContainerRepository::DestroyService.new(project, current_user).execute(container_repository) Projects::ContainerRepository::DestroyService.new(project, current_user).execute(container_repository)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# For ExclusiveLeaseGuard concern # For ExclusiveLeaseGuard concern
def lease_key def lease_key
......
...@@ -14,16 +14,14 @@ class DetectRepositoryLanguagesWorker # rubocop:disable Scalability/IdempotentWo ...@@ -14,16 +14,14 @@ class DetectRepositoryLanguagesWorker # rubocop:disable Scalability/IdempotentWo
attr_reader :project attr_reader :project
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id, user_id = nil) def perform(project_id, user_id = nil)
@project = Project.find_by(id: project_id) @project = Project.find_by_id(project_id)
return unless project return unless project
try_obtain_lease do try_obtain_lease do
::Projects::DetectRepositoryLanguagesService.new(project).execute ::Projects::DetectRepositoryLanguagesService.new(project).execute
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -9,17 +9,17 @@ class ExpireBuildInstanceArtifactsWorker # rubocop:disable Scalability/Idempoten ...@@ -9,17 +9,17 @@ class ExpireBuildInstanceArtifactsWorker # rubocop:disable Scalability/Idempoten
feature_category :build_artifacts feature_category :build_artifacts
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id) def perform(build_id)
# rubocop: disable CodeReuse/ActiveRecord
build = Ci::Build build = Ci::Build
.with_expired_artifacts .with_expired_artifacts
.reorder(nil) .reorder(nil)
.find_by(id: build_id) .find_by_id(build_id)
# rubocop: enable CodeReuse/ActiveRecord
return unless build&.project && !build.project.pending_delete return unless build&.project && !build.project.pending_delete
Gitlab::AppLogger.info("Removing artifacts for build #{build.id}...") Gitlab::AppLogger.info("Removing artifacts for build #{build.id}...")
build.erase_erasable_artifacts! build.erase_erasable_artifacts!
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -14,9 +14,8 @@ class ExpireJobCacheWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -14,9 +14,8 @@ class ExpireJobCacheWorker # rubocop:disable Scalability/IdempotentWorker
deduplicate :until_executing, including_scheduled: true deduplicate :until_executing, including_scheduled: true
idempotent! idempotent!
# rubocop: disable CodeReuse/ActiveRecord
def perform(job_id) def perform(job_id)
job = CommitStatus.preload(:pipeline, :project).find_by(id: job_id) job = CommitStatus.preload(:pipeline, :project).find_by_id(job_id) # rubocop: disable CodeReuse/ActiveRecord
return unless job return unless job
pipeline = job.pipeline pipeline = job.pipeline
...@@ -25,7 +24,6 @@ class ExpireJobCacheWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -25,7 +24,6 @@ class ExpireJobCacheWorker # rubocop:disable Scalability/IdempotentWorker
Gitlab::EtagCaching::Store.new.touch(project_job_path(project, job)) Gitlab::EtagCaching::Store.new.touch(project_job_path(project, job))
ExpirePipelineCacheWorker.perform_async(pipeline.id) ExpirePipelineCacheWorker.perform_async(pipeline.id)
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -17,13 +17,11 @@ class ExpirePipelineCacheWorker ...@@ -17,13 +17,11 @@ class ExpirePipelineCacheWorker
# Uncomment once https://gitlab.com/gitlab-org/gitlab/-/issues/325291 is resolved # Uncomment once https://gitlab.com/gitlab-org/gitlab/-/issues/325291 is resolved
# idempotent! # idempotent!
# rubocop: disable CodeReuse/ActiveRecord
def perform(pipeline_id) def perform(pipeline_id)
pipeline = Ci::Pipeline.find_by(id: pipeline_id) pipeline = Ci::Pipeline.find_by_id(pipeline_id)
return unless pipeline return unless pipeline
Ci::ExpirePipelineCacheService.new.execute(pipeline) Ci::ExpirePipelineCacheService.new.execute(pipeline)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
# rubocop:enable Scalability/IdempotentWorker # rubocop:enable Scalability/IdempotentWorker
...@@ -16,7 +16,7 @@ module Gitlab ...@@ -16,7 +16,7 @@ module Gitlab
attr_reader :project attr_reader :project
def perform(project_id) def perform(project_id)
@project = Project.find_by(id: project_id) # rubocop: disable CodeReuse/ActiveRecord @project = Project.find_by_id(project_id)
return unless start_import return unless start_import
......
...@@ -16,12 +16,11 @@ module HashedStorage ...@@ -16,12 +16,11 @@ module HashedStorage
attr_reader :project_id attr_reader :project_id
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id, old_disk_path = nil) def perform(project_id, old_disk_path = nil)
@project_id = project_id # we need to set this in order to create the lease_key @project_id = project_id # we need to set this in order to create the lease_key
try_obtain_lease do try_obtain_lease do
project = Project.without_deleted.find_by(id: project_id) project = Project.without_deleted.find_by_id(project_id)
break unless project && project.storage_upgradable? break unless project && project.storage_upgradable?
old_disk_path ||= Storage::LegacyProject.new(project).disk_path old_disk_path ||= Storage::LegacyProject.new(project).disk_path
...@@ -29,6 +28,5 @@ module HashedStorage ...@@ -29,6 +28,5 @@ module HashedStorage
::Projects::HashedStorage::MigrationService.new(project, old_disk_path, logger: logger).execute ::Projects::HashedStorage::MigrationService.new(project, old_disk_path, logger: logger).execute
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -16,12 +16,11 @@ module HashedStorage ...@@ -16,12 +16,11 @@ module HashedStorage
attr_reader :project_id attr_reader :project_id
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id, old_disk_path = nil) def perform(project_id, old_disk_path = nil)
@project_id = project_id # we need to set this in order to create the lease_key @project_id = project_id # we need to set this in order to create the lease_key
try_obtain_lease do try_obtain_lease do
project = Project.without_deleted.find_by(id: project_id) project = Project.without_deleted.find_by_id(project_id)
break unless project break unless project
old_disk_path ||= project.disk_path old_disk_path ||= project.disk_path
...@@ -29,6 +28,5 @@ module HashedStorage ...@@ -29,6 +28,5 @@ module HashedStorage
::Projects::HashedStorage::RollbackService.new(project, old_disk_path, logger: logger).execute ::Projects::HashedStorage::RollbackService.new(project, old_disk_path, logger: logger).execute
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -10,13 +10,11 @@ class InvalidGpgSignatureUpdateWorker # rubocop:disable Scalability/IdempotentWo ...@@ -10,13 +10,11 @@ class InvalidGpgSignatureUpdateWorker # rubocop:disable Scalability/IdempotentWo
feature_category :source_code_management feature_category :source_code_management
weight 2 weight 2
# rubocop: disable CodeReuse/ActiveRecord
def perform(gpg_key_id) def perform(gpg_key_id)
gpg_key = GpgKey.find_by(id: gpg_key_id) gpg_key = GpgKey.find_by_id(gpg_key_id)
return unless gpg_key return unless gpg_key
Gitlab::Gpg::InvalidGpgSignatureUpdater.new(gpg_key).run Gitlab::Gpg::InvalidGpgSignatureUpdater.new(gpg_key).run
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -14,14 +14,12 @@ class NewNoteWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -14,14 +14,12 @@ class NewNoteWorker # rubocop:disable Scalability/IdempotentWorker
# Keep extra parameter to preserve backwards compatibility with # Keep extra parameter to preserve backwards compatibility with
# old `NewNoteWorker` jobs (can remove later) # old `NewNoteWorker` jobs (can remove later)
# rubocop: disable CodeReuse/ActiveRecord
def perform(note_id, _params = {}) def perform(note_id, _params = {})
if note = Note.find_by(id: note_id) if note = Note.find_by_id(note_id)
NotificationService.new.new_note(note) unless note.skip_notification? NotificationService.new.new_note(note) unless note.skip_notification?
Notes::PostProcessService.new(note).execute Notes::PostProcessService.new(note).execute
else else
Gitlab::AppLogger.error("NewNoteWorker: couldn't find note with ID=#{note_id}, skipping job") Gitlab::AppLogger.error("NewNoteWorker: couldn't find note with ID=#{note_id}, skipping job")
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -9,15 +9,13 @@ class PagesDomainVerificationWorker # rubocop:disable Scalability/IdempotentWork ...@@ -9,15 +9,13 @@ class PagesDomainVerificationWorker # rubocop:disable Scalability/IdempotentWork
feature_category :pages feature_category :pages
# rubocop: disable CodeReuse/ActiveRecord
def perform(domain_id) def perform(domain_id)
return if Gitlab::Database.read_only? return if Gitlab::Database.read_only?
domain = PagesDomain.find_by(id: domain_id) domain = PagesDomain.find_by_id(domain_id)
return unless domain return unless domain
VerifyPagesDomainService.new(domain).execute VerifyPagesDomainService.new(domain).execute
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -14,15 +14,13 @@ class PagesWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -14,15 +14,13 @@ class PagesWorker # rubocop:disable Scalability/IdempotentWorker
send(action, *arg) # rubocop:disable GitlabSecurity/PublicSend send(action, *arg) # rubocop:disable GitlabSecurity/PublicSend
end end
# rubocop: disable CodeReuse/ActiveRecord
def deploy(build_id) def deploy(build_id)
build = Ci::Build.find_by(id: build_id) build = Ci::Build.find_by_id(build_id)
update_contents = Projects::UpdatePagesService.new(build.project, build).execute update_contents = Projects::UpdatePagesService.new(build.project, build).execute
if update_contents[:status] == :success if update_contents[:status] == :success
Projects::UpdatePagesConfigurationService.new(build.project).execute Projects::UpdatePagesConfigurationService.new(build.project).execute
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
def remove(namespace_path, project_path) def remove(namespace_path, project_path)
full_path = File.join(Settings.pages.path, namespace_path, project_path) full_path = File.join(Settings.pages.path, namespace_path, project_path)
......
...@@ -10,12 +10,10 @@ class PipelineHooksWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -10,12 +10,10 @@ class PipelineHooksWorker # rubocop:disable Scalability/IdempotentWorker
worker_resource_boundary :cpu worker_resource_boundary :cpu
data_consistency :delayed data_consistency :delayed
# rubocop: disable CodeReuse/ActiveRecord
def perform(pipeline_id) def perform(pipeline_id)
pipeline = Ci::Pipeline.find_by(id: pipeline_id) pipeline = Ci::Pipeline.find_by_id(pipeline_id)
return unless pipeline return unless pipeline
Ci::Pipelines::HookService.new(pipeline).execute Ci::Pipelines::HookService.new(pipeline).execute
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -10,14 +10,12 @@ class PipelineMetricsWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -10,14 +10,12 @@ class PipelineMetricsWorker # rubocop:disable Scalability/IdempotentWorker
urgency :high urgency :high
# rubocop: disable CodeReuse/ActiveRecord
def perform(pipeline_id) def perform(pipeline_id)
Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline| Ci::Pipeline.find_by_id(pipeline_id).try do |pipeline|
update_metrics_for_active_pipeline(pipeline) if pipeline.active? update_metrics_for_active_pipeline(pipeline) if pipeline.active?
update_metrics_for_succeeded_pipeline(pipeline) if pipeline.success? update_metrics_for_succeeded_pipeline(pipeline) if pipeline.success?
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
...@@ -29,11 +27,9 @@ class PipelineMetricsWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -29,11 +27,9 @@ class PipelineMetricsWorker # rubocop:disable Scalability/IdempotentWorker
metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: pipeline.finished_at, pipeline_id: pipeline.id) metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: pipeline.finished_at, pipeline_id: pipeline.id)
end end
# rubocop: disable CodeReuse/ActiveRecord
def metrics(pipeline) def metrics(pipeline)
MergeRequest::Metrics.where(merge_request_id: merge_requests(pipeline)) MergeRequest::Metrics.where(merge_request_id: merge_requests(pipeline)) # rubocop: disable CodeReuse/ActiveRecord
end end
# rubocop: enable CodeReuse/ActiveRecord
def merge_requests(pipeline) def merge_requests(pipeline)
pipeline.merge_requests_as_head_pipeline.map(&:id) pipeline.merge_requests_as_head_pipeline.map(&:id)
......
...@@ -16,13 +16,11 @@ class PipelineProcessWorker ...@@ -16,13 +16,11 @@ class PipelineProcessWorker
idempotent! idempotent!
deduplicate :until_executing deduplicate :until_executing
# rubocop: disable CodeReuse/ActiveRecord
def perform(pipeline_id) def perform(pipeline_id)
Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline| Ci::Pipeline.find_by_id(pipeline_id).try do |pipeline|
Ci::ProcessPipelineService Ci::ProcessPipelineService
.new(pipeline) .new(pipeline)
.execute .execute
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -23,9 +23,8 @@ class ProjectCacheWorker ...@@ -23,9 +23,8 @@ class ProjectCacheWorker
# refresh, if empty all columns will be refreshed # refresh, if empty all columns will be refreshed
# refresh_statistics - A boolean that determines whether project statistics should # refresh_statistics - A boolean that determines whether project statistics should
# be updated. # be updated.
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id, files = [], statistics = [], refresh_statistics = true) def perform(project_id, files = [], statistics = [], refresh_statistics = true)
project = Project.find_by(id: project_id) project = Project.find_by_id(project_id)
return unless project return unless project
...@@ -37,7 +36,6 @@ class ProjectCacheWorker ...@@ -37,7 +36,6 @@ class ProjectCacheWorker
project.cleanup project.cleanup
end end
# rubocop: enable CodeReuse/ActiveRecord
# NOTE: triggering both an immediate update and one in 15 minutes if we # NOTE: triggering both an immediate update and one in 15 minutes if we
# successfully obtain the lease. That way, we only need to wait for the # successfully obtain the lease. That way, we only need to wait for the
......
...@@ -13,13 +13,11 @@ class PropagateServiceTemplateWorker # rubocop:disable Scalability/IdempotentWor ...@@ -13,13 +13,11 @@ class PropagateServiceTemplateWorker # rubocop:disable Scalability/IdempotentWor
LEASE_TIMEOUT = 4.hours.to_i LEASE_TIMEOUT = 4.hours.to_i
# rubocop: disable CodeReuse/ActiveRecord
def perform(template_id) def perform(template_id)
return unless try_obtain_lease_for(template_id) return unless try_obtain_lease_for(template_id)
Admin::PropagateServiceTemplate.propagate(Integration.find_by(id: template_id)) Admin::PropagateServiceTemplate.propagate(Integration.find_by_id(template_id))
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -11,16 +11,14 @@ class RunPipelineScheduleWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -11,16 +11,14 @@ class RunPipelineScheduleWorker # rubocop:disable Scalability/IdempotentWorker
queue_namespace :pipeline_creation queue_namespace :pipeline_creation
feature_category :continuous_integration feature_category :continuous_integration
# rubocop: disable CodeReuse/ActiveRecord
def perform(schedule_id, user_id) def perform(schedule_id, user_id)
schedule = Ci::PipelineSchedule.find_by(id: schedule_id) schedule = Ci::PipelineSchedule.find_by_id(schedule_id)
user = User.find_by(id: user_id) user = User.find_by_id(user_id)
return unless schedule && user return unless schedule && user
run_pipeline_schedule(schedule, user) run_pipeline_schedule(schedule, user)
end end
# rubocop: enable CodeReuse/ActiveRecord
def run_pipeline_schedule(schedule, user) def run_pipeline_schedule(schedule, user)
Ci::CreatePipelineService.new(schedule.project, Ci::CreatePipelineService.new(schedule.project,
......
...@@ -13,17 +13,15 @@ class UpdateHighestRoleWorker ...@@ -13,17 +13,15 @@ class UpdateHighestRoleWorker
idempotent! idempotent!
# rubocop: disable CodeReuse/ActiveRecord
def perform(user_id) def perform(user_id)
user = User.find_by(id: user_id) user = User.find_by_id(user_id)
return unless user.present? return unless user.present?
if user.active? && user.human? && !user.internal? if user.active? && user.human? && !user.internal?
Users::UpdateHighestMemberRoleService.new(user).execute Users::UpdateHighestMemberRoleService.new(user).execute
else else
UserHighestRole.where(user_id: user_id).delete_all UserHighestRole.where(user_id: user_id).delete_all # rubocop: disable CodeReuse/ActiveRecord
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -13,15 +13,13 @@ class UpdateMergeRequestsWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -13,15 +13,13 @@ class UpdateMergeRequestsWorker # rubocop:disable Scalability/IdempotentWorker
weight 3 weight 3
loggable_arguments 2, 3, 4 loggable_arguments 2, 3, 4
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id, user_id, oldrev, newrev, ref) def perform(project_id, user_id, oldrev, newrev, ref)
project = Project.find_by(id: project_id) project = Project.find_by_id(project_id)
return unless project return unless project
user = User.find_by(id: user_id) user = User.find_by_id(user_id)
return unless user return unless user
MergeRequests::RefreshService.new(project: project, current_user: user).execute(oldrev, newrev, ref) MergeRequests::RefreshService.new(project: project, current_user: user).execute(oldrev, newrev, ref)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -13,11 +13,9 @@ class UpdateProjectStatisticsWorker # rubocop:disable Scalability/IdempotentWork ...@@ -13,11 +13,9 @@ class UpdateProjectStatisticsWorker # rubocop:disable Scalability/IdempotentWork
# project_id - The ID of the project for which to flush the cache. # project_id - The ID of the project for which to flush the cache.
# statistics - An Array containing columns from ProjectStatistics to # statistics - An Array containing columns from ProjectStatistics to
# refresh, if empty all columns will be refreshed # refresh, if empty all columns will be refreshed
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id, statistics = []) def perform(project_id, statistics = [])
project = Project.find_by(id: project_id) project = Project.find_by_id(project_id)
Projects::UpdateStatisticsService.new(project, nil, statistics: statistics).execute Projects::UpdateStatisticsService.new(project, nil, statistics: statistics).execute
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -12,9 +12,8 @@ module Analytics ...@@ -12,9 +12,8 @@ module Analytics
MODEL_KLASSES = %w[Issue MergeRequest].freeze MODEL_KLASSES = %w[Issue MergeRequest].freeze
# rubocop: disable CodeReuse/ActiveRecord
def perform(group_id, model_klass = MODEL_KLASSES.first, cursor = {}, updated_at_before = Time.current) def perform(group_id, model_klass = MODEL_KLASSES.first, cursor = {}, updated_at_before = Time.current)
group = Group.find_by(id: group_id) group = Group.find_by_id(group_id)
return unless group return unless group
model = model_klass.safe_constantize model = model_klass.safe_constantize
...@@ -51,7 +50,6 @@ module Analytics ...@@ -51,7 +50,6 @@ module Analytics
true true
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
...@@ -18,14 +18,12 @@ module EE ...@@ -18,14 +18,12 @@ module EE
# Geo should only update Redis based cache, as data store in the database # Geo should only update Redis based cache, as data store in the database
# will be updated on primary and replicated to the secondaries. # will be updated on primary and replicated to the secondaries.
# rubocop: disable CodeReuse/ActiveRecord
def perform_geo_secondary(project_id, refresh = [], _statistics = []) def perform_geo_secondary(project_id, refresh = [], _statistics = [])
project = ::Project.find_by(id: project_id) project = ::Project.find_by_id(project_id)
return unless project && project.repository.exists? return unless project && project.repository.exists?
project.repository.refresh_method_caches(refresh.map(&:to_sym)) project.repository.refresh_method_caches(refresh.map(&:to_sym))
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -16,18 +16,16 @@ module Geo ...@@ -16,18 +16,16 @@ module Geo
attr_reader :project attr_reader :project
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id) def perform(project_id)
return unless Gitlab::Geo.primary? return unless Gitlab::Geo.primary?
@project = Project.find_by(id: project_id) @project = Project.find_by_id(project_id)
return if project.nil? || project.pending_delete? return if project.nil? || project.pending_delete?
try_obtain_lease do try_obtain_lease do
Geo::RepositoryVerificationPrimaryService.new(project).execute Geo::RepositoryVerificationPrimaryService.new(project).execute
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -20,11 +20,10 @@ module Geo ...@@ -20,11 +20,10 @@ module Geo
delegate :project, to: :registry delegate :project, to: :registry
# rubocop: disable CodeReuse/ActiveRecord
def perform(registry_id) def perform(registry_id)
return unless Gitlab::Geo.secondary? return unless Gitlab::Geo.secondary?
@registry = Geo::ProjectRegistry.find_by(id: registry_id) @registry = Geo::ProjectRegistry.find_by_id(registry_id)
return if registry.nil? || project.nil? || project.pending_delete? return if registry.nil? || project.nil? || project.pending_delete?
try_obtain_lease do try_obtain_lease do
...@@ -32,7 +31,6 @@ module Geo ...@@ -32,7 +31,6 @@ module Geo
verify_checksum(:wiki) verify_checksum(:wiki)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -12,15 +12,13 @@ class MergeRequestResetApprovalsWorker # rubocop:disable Scalability/IdempotentW ...@@ -12,15 +12,13 @@ class MergeRequestResetApprovalsWorker # rubocop:disable Scalability/IdempotentW
worker_resource_boundary :cpu worker_resource_boundary :cpu
loggable_arguments 2, 3 loggable_arguments 2, 3
# rubocop: disable CodeReuse/ActiveRecord
def perform(project_id, user_id, ref, newrev) def perform(project_id, user_id, ref, newrev)
project = Project.find_by(id: project_id) project = Project.find_by_id(project_id)
return unless project return unless project
user = User.find_by(id: user_id) user = User.find_by_id(user_id)
return unless user return unless user
MergeRequests::ResetApprovalsService.new(project: project, current_user: user).execute(ref, newrev) MergeRequests::ResetApprovalsService.new(project: project, current_user: user).execute(ref, newrev)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -12,11 +12,10 @@ module Security ...@@ -12,11 +12,10 @@ module Security
idempotent! idempotent!
# rubocop: disable CodeReuse/ActiveRecord
def perform(pipeline_id) def perform(pipeline_id)
return if Feature.disabled?(:security_auto_fix) return if Feature.disabled?(:security_auto_fix)
::Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline| ::Ci::Pipeline.find_by_id(pipeline_id).try do |pipeline|
project = pipeline.project project = pipeline.project
break unless project.security_setting.auto_fix_enabled? break unless project.security_setting.auto_fix_enabled?
...@@ -24,6 +23,5 @@ module Security ...@@ -24,6 +23,5 @@ module Security
Security::AutoFixService.new(project, pipeline).execute Security::AutoFixService.new(project, pipeline).execute
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
...@@ -12,9 +12,8 @@ module Security ...@@ -12,9 +12,8 @@ module Security
feature_category :vulnerability_management feature_category :vulnerability_management
# rubocop: disable CodeReuse/ActiveRecord
def perform(pipeline_id) def perform(pipeline_id)
::Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline| ::Ci::Pipeline.find_by_id(pipeline_id).try do |pipeline|
break unless pipeline.can_store_security_reports? break unless pipeline.can_store_security_reports?
record_onboarding_progress(pipeline) record_onboarding_progress(pipeline)
......
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