diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2018-10-08 10:40:10 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2018-10-08 10:40:10 +0100 |
commit | fa875ba7a9441df6827ef1d6b05405c66ee0c579 (patch) | |
tree | 23d0cf911c9bf6a73fec9bb1f3de1bf61bedeacd /app/workers | |
parent | ecefe090460687a078e3d1aacf621fd5bff07fb5 (diff) | |
parent | 838c1076694d24d180e19625d663749c8b5c1a1c (diff) | |
download | gitlab-ce-fa875ba7a9441df6827ef1d6b05405c66ee0c579.tar.gz |
Merge branch 'master' into 42611-removed-branch-link
* master: (1252 commits)
Render log artifact files in GitLab
Check disabled_services when finding a service
Fix invalid parent path on group settings page
Backport CE changes for: [Frontend only] Batch comments on merge requests
Add button to insert table in markdown editor
Update GITALY_SERVER_VERSION
Updates Laravel.gitlab-ci.yml template
Update operations metrics empty state
Fix LFS uploaded images not being rendered
Prepare admin/projects/show view to allow EE specific feature
Add timed incremental rollout to Auto DevOps
Update spec comment to point to correct issue
Fix documentation for variables
Document Security and Licence Management features permissions
Fix time dependent jobs spec
Use a CTE to remove the query timeout
Backport changes from gitlab-ee!7538
Fix CE to EE merge (backport)
Add changelog entry
Refactor Feature.flipper method
...
Diffstat (limited to 'app/workers')
61 files changed, 257 insertions, 16 deletions
diff --git a/app/workers/admin_email_worker.rb b/app/workers/admin_email_worker.rb index 06324575ffc..f69e74b2674 100644 --- a/app/workers/admin_email_worker.rb +++ b/app/workers/admin_email_worker.rb @@ -10,10 +10,12 @@ class AdminEmailWorker private + # rubocop: disable CodeReuse/ActiveRecord def send_repository_check_mail repository_check_failed_count = Project.where(last_repository_check_failed: true).count return if repository_check_failed_count.zero? RepositoryCheckMailer.notify(repository_check_failed_count).deliver_now end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml index f95df7ecf03..f21789de37d 100644 --- a/app/workers/all_queues.yml +++ b/app/workers/all_queues.yml @@ -1,4 +1,6 @@ --- +- auto_devops:auto_devops_disable + - cronjob:admin_email - cronjob:expire_build_artifacts - cronjob:gitlab_usage_ping @@ -68,6 +70,7 @@ - pipeline_processing:pipeline_update - pipeline_processing:stage_update - pipeline_processing:update_head_pipeline_for_merge_request +- pipeline_processing:ci_build_schedule - repository_check:repository_check_clear - repository_check:repository_check_batch @@ -85,6 +88,7 @@ - authorized_projects - background_migration - create_gpg_signature +- delete_container_repository - delete_merged_branches - delete_user - email_receiver diff --git a/app/workers/archive_trace_worker.rb b/app/workers/archive_trace_worker.rb index c6f89a17729..c1283e9b2fc 100644 --- a/app/workers/archive_trace_worker.rb +++ b/app/workers/archive_trace_worker.rb @@ -4,9 +4,11 @@ class ArchiveTraceWorker include ApplicationWorker include PipelineBackgroundQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(job_id) Ci::Build.without_archived_trace.find_by(id: job_id).try do |job| job.trace.archive! end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/authorized_projects_worker.rb b/app/workers/authorized_projects_worker.rb index dd62bb0f33d..c9ddeb08613 100644 --- a/app/workers/authorized_projects_worker.rb +++ b/app/workers/authorized_projects_worker.rb @@ -12,9 +12,11 @@ class AuthorizedProjectsWorker end end + # rubocop: disable CodeReuse/ActiveRecord def perform(user_id) user = User.find_by(id: user_id) user&.refresh_authorized_projects end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/auto_devops/disable_worker.rb b/app/workers/auto_devops/disable_worker.rb new file mode 100644 index 00000000000..73ddc591505 --- /dev/null +++ b/app/workers/auto_devops/disable_worker.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module AutoDevops + class DisableWorker + include ApplicationWorker + include AutoDevopsQueue + + def perform(pipeline_id) + pipeline = Ci::Pipeline.find(pipeline_id) + project = pipeline.project + + send_notification_email(pipeline, project) if disable_service(project).execute + end + + private + + def disable_service(project) + Projects::AutoDevops::DisableService.new(project) + end + + def send_notification_email(pipeline, project) + recipients = email_receivers_for(pipeline, project) + + return unless recipients.any? + + NotificationService.new.autodevops_disabled(pipeline, recipients) + end + + def email_receivers_for(pipeline, project) + recipients = [pipeline.user&.email] + recipients << project.owner.email unless project.group + recipients.uniq.compact + end + end +end diff --git a/app/workers/build_coverage_worker.rb b/app/workers/build_coverage_worker.rb index 53d77dc4524..912c53e11f8 100644 --- a/app/workers/build_coverage_worker.rb +++ b/app/workers/build_coverage_worker.rb @@ -4,7 +4,9 @@ class BuildCoverageWorker include ApplicationWorker include PipelineQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id)&.update_coverage end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/build_finished_worker.rb b/app/workers/build_finished_worker.rb index 9dc2c7f3601..51cbbe8882e 100644 --- a/app/workers/build_finished_worker.rb +++ b/app/workers/build_finished_worker.rb @@ -6,6 +6,7 @@ class BuildFinishedWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id).try do |build| # We execute that in sync as this access the files in order to access local file, and reduce IO @@ -17,4 +18,5 @@ class BuildFinishedWorker ArchiveTraceWorker.perform_async(build.id) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/build_hooks_worker.rb b/app/workers/build_hooks_worker.rb index f1f71dc589c..b0c3676714c 100644 --- a/app/workers/build_hooks_worker.rb +++ b/app/workers/build_hooks_worker.rb @@ -6,8 +6,10 @@ class BuildHooksWorker queue_namespace :pipeline_hooks + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id) .try(:execute_hooks) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/build_queue_worker.rb b/app/workers/build_queue_worker.rb index 1b3f1fd3c2a..67d5b0f5f5b 100644 --- a/app/workers/build_queue_worker.rb +++ b/app/workers/build_queue_worker.rb @@ -6,9 +6,11 @@ class BuildQueueWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id).try do |build| Ci::UpdateBuildQueueService.new.execute(build) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/build_success_worker.rb b/app/workers/build_success_worker.rb index e1c1cc24a94..c17608f7378 100644 --- a/app/workers/build_success_worker.rb +++ b/app/workers/build_success_worker.rb @@ -6,11 +6,13 @@ class BuildSuccessWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id).try do |build| create_deployment(build) if build.has_environment? end end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/workers/build_trace_sections_worker.rb b/app/workers/build_trace_sections_worker.rb index f4114b3353c..0641130fd64 100644 --- a/app/workers/build_trace_sections_worker.rb +++ b/app/workers/build_trace_sections_worker.rb @@ -4,7 +4,9 @@ class BuildTraceSectionsWorker include ApplicationWorker include PipelineQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id)&.parse_trace_sections! end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/ci/archive_traces_cron_worker.rb b/app/workers/ci/archive_traces_cron_worker.rb index 7d4e9660a4e..7443aad1380 100644 --- a/app/workers/ci/archive_traces_cron_worker.rb +++ b/app/workers/ci/archive_traces_cron_worker.rb @@ -5,6 +5,7 @@ module Ci include ApplicationWorker include CronjobQueue + # rubocop: disable CodeReuse/ActiveRecord def perform # Archive stale live traces which still resides in redis or database # This could happen when ArchiveTraceWorker sidekiq jobs were lost by receiving SIGKILL @@ -19,6 +20,7 @@ module Ci end end end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/workers/ci/build_schedule_worker.rb b/app/workers/ci/build_schedule_worker.rb new file mode 100644 index 00000000000..da219adffc6 --- /dev/null +++ b/app/workers/ci/build_schedule_worker.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Ci + class BuildScheduleWorker + include ApplicationWorker + include PipelineQueue + + queue_namespace :pipeline_processing + + def perform(build_id) + ::Ci::Build.find_by_id(build_id).try do |build| + break unless build.scheduled? + + Ci::RunScheduledBuildService + .new(build.project, build.user).execute(build) + end + end + end +end diff --git a/app/workers/ci/build_trace_chunk_flush_worker.rb b/app/workers/ci/build_trace_chunk_flush_worker.rb index 9dbf2e5e1ac..23a11c28f9b 100644 --- a/app/workers/ci/build_trace_chunk_flush_worker.rb +++ b/app/workers/ci/build_trace_chunk_flush_worker.rb @@ -5,10 +5,12 @@ module Ci include ApplicationWorker include PipelineBackgroundQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(build_trace_chunk_id) ::Ci::BuildTraceChunk.find_by(id: build_trace_chunk_id).try do |build_trace_chunk| build_trace_chunk.persist_data! end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/workers/concerns/auto_devops_queue.rb b/app/workers/concerns/auto_devops_queue.rb new file mode 100644 index 00000000000..aba928ccaab --- /dev/null +++ b/app/workers/concerns/auto_devops_queue.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true +# +module AutoDevopsQueue + extend ActiveSupport::Concern + + included do + queue_namespace :auto_devops + end +end diff --git a/app/workers/concerns/gitlab/github_import/rescheduling_methods.rb b/app/workers/concerns/gitlab/github_import/rescheduling_methods.rb index 692ca6b7f42..1c6413674a0 100644 --- a/app/workers/concerns/gitlab/github_import/rescheduling_methods.rb +++ b/app/workers/concerns/gitlab/github_import/rescheduling_methods.rb @@ -8,6 +8,7 @@ module Gitlab # project_id - The ID of the GitLab project to import the note into. # hash - A Hash containing the details of the GitHub object to imoprt. # notify_key - The Redis key to notify upon completion, if any. + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, hash, notify_key = nil) project = Project.find_by(id: project_id) @@ -24,6 +25,7 @@ module Gitlab .perform_in(client.rate_limit_resets_in, project.id, hash, notify_key) end end + # rubocop: enable CodeReuse/ActiveRecord def try_import(*args) import(*args) diff --git a/app/workers/concerns/gitlab/github_import/stage_methods.rb b/app/workers/concerns/gitlab/github_import/stage_methods.rb index 147c8c8d683..59e6bc2c97d 100644 --- a/app/workers/concerns/gitlab/github_import/stage_methods.rb +++ b/app/workers/concerns/gitlab/github_import/stage_methods.rb @@ -20,11 +20,13 @@ module Gitlab self.class.perform_in(client.rate_limit_resets_in, project.id) end + # rubocop: disable CodeReuse/ActiveRecord def find_project(id) # If the project has been marked as failed we want to bail out # automatically. Project.import_started.find_by(id: id) end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/workers/concerns/new_issuable.rb b/app/workers/concerns/new_issuable.rb index 7735dec5e6b..a89451a4475 100644 --- a/app/workers/concerns/new_issuable.rb +++ b/app/workers/concerns/new_issuable.rb @@ -10,17 +10,21 @@ module NewIssuable user && issuable end + # rubocop: disable CodeReuse/ActiveRecord def set_user(user_id) @user = User.find_by(id: user_id) # rubocop:disable Gitlab/ModuleWithInstanceVariables log_error(User, user_id) unless @user # rubocop:disable Gitlab/ModuleWithInstanceVariables end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def set_issuable(issuable_id) @issuable = issuable_class.find_by(id: issuable_id) # rubocop:disable Gitlab/ModuleWithInstanceVariables log_error(issuable_class, issuable_id) unless @issuable # rubocop:disable Gitlab/ModuleWithInstanceVariables end + # rubocop: enable CodeReuse/ActiveRecord def log_error(record_class, record_id) Rails.logger.error("#{self.class}: couldn't find #{record_class} with ID=#{record_id}, skipping job") diff --git a/app/workers/create_gpg_signature_worker.rb b/app/workers/create_gpg_signature_worker.rb index a1aeeb7c4fc..49c7a403838 100644 --- a/app/workers/create_gpg_signature_worker.rb +++ b/app/workers/create_gpg_signature_worker.rb @@ -3,6 +3,7 @@ class CreateGpgSignatureWorker include ApplicationWorker + # rubocop: disable CodeReuse/ActiveRecord def perform(commit_shas, project_id) # Older versions of GitPushService may push a single commit ID on the stack. # We need this to be backwards compatible. @@ -26,4 +27,5 @@ class CreateGpgSignatureWorker end end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/delete_container_repository_worker.rb b/app/workers/delete_container_repository_worker.rb new file mode 100644 index 00000000000..e8fe9d82797 --- /dev/null +++ b/app/workers/delete_container_repository_worker.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +class DeleteContainerRepositoryWorker + include ApplicationWorker + include ExclusiveLeaseGuard + + LEASE_TIMEOUT = 1.hour + + attr_reader :container_repository + + # rubocop: disable CodeReuse/ActiveRecord + def perform(current_user_id, container_repository_id) + current_user = User.find_by(id: current_user_id) + @container_repository = ContainerRepository.find_by(id: container_repository_id) + project = container_repository&.project + + return unless current_user && container_repository && project + + # If a user accidentally attempts to delete the same container registry in quick succession, + # this can lead to orphaned tags. + try_obtain_lease do + Projects::ContainerRepository::DestroyService.new(project, current_user).execute(container_repository) + end + end + # rubocop: enable CodeReuse/ActiveRecord + + # For ExclusiveLeaseGuard concern + def lease_key + @lease_key ||= "container_repository:delete:#{container_repository.id}" + end + + # For ExclusiveLeaseGuard concern + def lease_timeout + LEASE_TIMEOUT + end +end diff --git a/app/workers/delete_diff_files_worker.rb b/app/workers/delete_diff_files_worker.rb index 0874a0b75e8..f518dfe871c 100644 --- a/app/workers/delete_diff_files_worker.rb +++ b/app/workers/delete_diff_files_worker.rb @@ -3,6 +3,7 @@ class DeleteDiffFilesWorker include ApplicationWorker + # rubocop: disable CodeReuse/ActiveRecord def perform(merge_request_diff_id) merge_request_diff = MergeRequestDiff.find(merge_request_diff_id) @@ -16,4 +17,5 @@ class DeleteDiffFilesWorker .delete_all end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/detect_repository_languages_worker.rb b/app/workers/detect_repository_languages_worker.rb index 854b74b884a..64bc9776d48 100644 --- a/app/workers/detect_repository_languages_worker.rb +++ b/app/workers/detect_repository_languages_worker.rb @@ -11,6 +11,7 @@ class DetectRepositoryLanguagesWorker attr_reader :project + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, user_id) @project = Project.find_by(id: project_id) user = User.find_by(id: user_id) @@ -20,6 +21,7 @@ class DetectRepositoryLanguagesWorker ::Projects::DetectRepositoryLanguagesService.new(project, user).execute end end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/workers/expire_build_artifacts_worker.rb b/app/workers/expire_build_artifacts_worker.rb index 5d3a9a39b93..dce812d1ae2 100644 --- a/app/workers/expire_build_artifacts_worker.rb +++ b/app/workers/expire_build_artifacts_worker.rb @@ -4,6 +4,7 @@ class ExpireBuildArtifactsWorker include ApplicationWorker include CronjobQueue + # rubocop: disable CodeReuse/ActiveRecord def perform Rails.logger.info 'Scheduling removal of build artifacts' @@ -12,4 +13,5 @@ class ExpireBuildArtifactsWorker ExpireBuildInstanceArtifactsWorker.bulk_perform_async(build_ids) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/expire_build_instance_artifacts_worker.rb b/app/workers/expire_build_instance_artifacts_worker.rb index 3b57ecb36e3..94426dcf921 100644 --- a/app/workers/expire_build_instance_artifacts_worker.rb +++ b/app/workers/expire_build_instance_artifacts_worker.rb @@ -3,6 +3,7 @@ class ExpireBuildInstanceArtifactsWorker include ApplicationWorker + # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) build = Ci::Build .with_expired_artifacts @@ -12,6 +13,7 @@ class ExpireBuildInstanceArtifactsWorker return unless build&.project && !build.project.pending_delete Rails.logger.info "Removing artifacts for build #{build.id}..." - build.erase_artifacts! + build.erase_erasable_artifacts! end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/expire_job_cache_worker.rb b/app/workers/expire_job_cache_worker.rb index 14a57b90114..b09d0a5d121 100644 --- a/app/workers/expire_job_cache_worker.rb +++ b/app/workers/expire_job_cache_worker.rb @@ -6,6 +6,7 @@ class ExpireJobCacheWorker queue_namespace :pipeline_cache + # rubocop: disable CodeReuse/ActiveRecord def perform(job_id) job = CommitStatus.joins(:pipeline, :project).find_by(id: job_id) return unless job @@ -18,6 +19,7 @@ class ExpireJobCacheWorker store.touch(project_job_path(project, job)) end end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/workers/expire_pipeline_cache_worker.rb b/app/workers/expire_pipeline_cache_worker.rb index 992fc63c451..c96e8a0379b 100644 --- a/app/workers/expire_pipeline_cache_worker.rb +++ b/app/workers/expire_pipeline_cache_worker.rb @@ -6,6 +6,7 @@ class ExpirePipelineCacheWorker queue_namespace :pipeline_cache + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id) pipeline = Ci::Pipeline.find_by(id: pipeline_id) return unless pipeline @@ -23,6 +24,7 @@ class ExpirePipelineCacheWorker Gitlab::Cache::Ci::ProjectPipelineStatus.update_for_pipeline(pipeline) end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/workers/gitlab/github_import/advance_stage_worker.rb b/app/workers/gitlab/github_import/advance_stage_worker.rb index be0b6c180b0..cd2ceb8dcdf 100644 --- a/app/workers/gitlab/github_import/advance_stage_worker.rb +++ b/app/workers/gitlab/github_import/advance_stage_worker.rb @@ -63,12 +63,14 @@ module Gitlab end end + # rubocop: disable CodeReuse/ActiveRecord def find_project(id) # TODO: Only select the JID # This is due to the fact that the JID could be present in either the project record or # its associated import_state record Project.import_started.find_by(id: id) end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/workers/gitlab/github_import/refresh_import_jid_worker.rb b/app/workers/gitlab/github_import/refresh_import_jid_worker.rb index 68d2c5c4331..65473026b4c 100644 --- a/app/workers/gitlab/github_import/refresh_import_jid_worker.rb +++ b/app/workers/gitlab/github_import/refresh_import_jid_worker.rb @@ -30,12 +30,14 @@ module Gitlab # stage, if it died there's nothing we can do anyway. end + # rubocop: disable CodeReuse/ActiveRecord def find_project(id) # TODO: Only select the JID # This is due to the fact that the JID could be present in either the project record or # its associated import_state record Project.import_started.find_by(id: id) end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/workers/invalid_gpg_signature_update_worker.rb b/app/workers/invalid_gpg_signature_update_worker.rb index 4724ab7ad98..fc8a731b427 100644 --- a/app/workers/invalid_gpg_signature_update_worker.rb +++ b/app/workers/invalid_gpg_signature_update_worker.rb @@ -3,6 +3,7 @@ class InvalidGpgSignatureUpdateWorker include ApplicationWorker + # rubocop: disable CodeReuse/ActiveRecord def perform(gpg_key_id) gpg_key = GpgKey.find_by(id: gpg_key_id) @@ -10,4 +11,5 @@ class InvalidGpgSignatureUpdateWorker Gitlab::Gpg::InvalidGpgSignatureUpdater.new(gpg_key).run end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/issue_due_scheduler_worker.rb b/app/workers/issue_due_scheduler_worker.rb index c04a2d75e0b..476cba47ad7 100644 --- a/app/workers/issue_due_scheduler_worker.rb +++ b/app/workers/issue_due_scheduler_worker.rb @@ -4,9 +4,11 @@ class IssueDueSchedulerWorker include ApplicationWorker include CronjobQueue + # rubocop: disable CodeReuse/ActiveRecord def perform project_ids = Issue.opened.due_tomorrow.group(:project_id).pluck(:project_id).map { |id| [id] } MailScheduler::IssueDueWorker.bulk_perform_async(project_ids) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/mail_scheduler/issue_due_worker.rb b/app/workers/mail_scheduler/issue_due_worker.rb index 8794ad7a82c..1e1dde1e829 100644 --- a/app/workers/mail_scheduler/issue_due_worker.rb +++ b/app/workers/mail_scheduler/issue_due_worker.rb @@ -5,10 +5,12 @@ module MailScheduler include ApplicationWorker include MailSchedulerQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id) Issue.opened.due_tomorrow.in_projects(project_id).preload(:project).find_each do |issue| notification_service.issue_due(issue) end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/workers/new_merge_request_worker.rb b/app/workers/new_merge_request_worker.rb index 5d8b8904502..fa48c1b29a8 100644 --- a/app/workers/new_merge_request_worker.rb +++ b/app/workers/new_merge_request_worker.rb @@ -9,6 +9,8 @@ class NewMergeRequestWorker EventCreateService.new.open_mr(issuable, user) NotificationService.new.new_merge_request(issuable, user) + + issuable.diffs(include_stats: false).write_cache issuable.create_cross_references!(user) end diff --git a/app/workers/new_note_worker.rb b/app/workers/new_note_worker.rb index 74f34dcf9aa..42f5b945a75 100644 --- a/app/workers/new_note_worker.rb +++ b/app/workers/new_note_worker.rb @@ -5,6 +5,7 @@ class NewNoteWorker # Keep extra parameter to preserve backwards compatibility with # old `NewNoteWorker` jobs (can remove later) + # rubocop: disable CodeReuse/ActiveRecord def perform(note_id, _params = {}) if note = Note.find_by(id: note_id) NotificationService.new.new_note(note) @@ -13,4 +14,5 @@ class NewNoteWorker Rails.logger.error("NewNoteWorker: couldn't find note with ID=#{note_id}, skipping job") end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/object_storage/migrate_uploads_worker.rb b/app/workers/object_storage/migrate_uploads_worker.rb index 01d03ec7888..fe5d27b087d 100644 --- a/app/workers/object_storage/migrate_uploads_worker.rb +++ b/app/workers/object_storage/migrate_uploads_worker.rb @@ -57,11 +57,13 @@ module ObjectStorage include Report + # rubocop: disable CodeReuse/ActiveRecord def self.enqueue!(uploads, model_class, mounted_as, to_store) sanity_check!(uploads, model_class, mounted_as) perform_async(uploads.ids, model_class.to_s, mounted_as, to_store) end + # rubocop: enable CodeReuse/ActiveRecord # We need to be sure all the uploads are for the same uploader and model type # and that the mount point exists if provided. @@ -78,6 +80,7 @@ module ObjectStorage raise(SanityCheckError, "Mount point #{mounted_as} not found in #{model_class}.") unless model_has_mount end + # rubocop: disable CodeReuse/ActiveRecord def perform(*args) args_check!(args) @@ -97,6 +100,7 @@ module ObjectStorage # do not retry: the job is insane Rails.logger.warn "#{self.class}: Sanity check error (#{e.message})" end + # rubocop: enable CodeReuse/ActiveRecord def sanity_check!(uploads) self.class.sanity_check!(uploads, @model_class, @mounted_as) diff --git a/app/workers/pages_domain_verification_worker.rb b/app/workers/pages_domain_verification_worker.rb index 4610b688189..b3319ff5a13 100644 --- a/app/workers/pages_domain_verification_worker.rb +++ b/app/workers/pages_domain_verification_worker.rb @@ -3,6 +3,7 @@ class PagesDomainVerificationWorker include ApplicationWorker + # rubocop: disable CodeReuse/ActiveRecord def perform(domain_id) domain = PagesDomain.find_by(id: domain_id) @@ -10,4 +11,5 @@ class PagesDomainVerificationWorker VerifyPagesDomainService.new(domain).execute end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/pages_worker.rb b/app/workers/pages_worker.rb index 13a6576a301..fa0dfa2ff4b 100644 --- a/app/workers/pages_worker.rb +++ b/app/workers/pages_worker.rb @@ -9,6 +9,7 @@ class PagesWorker send(action, *arg) # rubocop:disable GitlabSecurity/PublicSend end + # rubocop: disable CodeReuse/ActiveRecord def deploy(build_id) build = Ci::Build.find_by(id: build_id) result = Projects::UpdatePagesService.new(build.project, build).execute @@ -18,6 +19,7 @@ class PagesWorker result end + # rubocop: enable CodeReuse/ActiveRecord def remove(namespace_path, project_path) full_path = File.join(Settings.pages.path, namespace_path, project_path) diff --git a/app/workers/pipeline_hooks_worker.rb b/app/workers/pipeline_hooks_worker.rb index 58023e0af1b..eae1115e60c 100644 --- a/app/workers/pipeline_hooks_worker.rb +++ b/app/workers/pipeline_hooks_worker.rb @@ -6,8 +6,10 @@ class PipelineHooksWorker queue_namespace :pipeline_hooks + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id) Ci::Pipeline.find_by(id: pipeline_id) .try(:execute_hooks) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/pipeline_metrics_worker.rb b/app/workers/pipeline_metrics_worker.rb index a97019b100a..c2fbfd2b3a5 100644 --- a/app/workers/pipeline_metrics_worker.rb +++ b/app/workers/pipeline_metrics_worker.rb @@ -4,12 +4,14 @@ class PipelineMetricsWorker include ApplicationWorker include PipelineQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id) Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline| update_metrics_for_active_pipeline(pipeline) if pipeline.active? update_metrics_for_succeeded_pipeline(pipeline) if pipeline.success? end end + # rubocop: enable CodeReuse/ActiveRecord private @@ -21,9 +23,11 @@ class PipelineMetricsWorker metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: pipeline.finished_at, pipeline_id: pipeline.id) end + # rubocop: disable CodeReuse/ActiveRecord def metrics(pipeline) MergeRequest::Metrics.where(merge_request_id: merge_requests(pipeline)) end + # rubocop: enable CodeReuse/ActiveRecord def merge_requests(pipeline) pipeline.merge_requests.map(&:id) diff --git a/app/workers/pipeline_notification_worker.rb b/app/workers/pipeline_notification_worker.rb index 3a8846b3747..e4a18573d20 100644 --- a/app/workers/pipeline_notification_worker.rb +++ b/app/workers/pipeline_notification_worker.rb @@ -4,6 +4,7 @@ class PipelineNotificationWorker include ApplicationWorker include PipelineQueue + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id, recipients = nil) pipeline = Ci::Pipeline.find_by(id: pipeline_id) @@ -11,4 +12,5 @@ class PipelineNotificationWorker NotificationService.new.pipeline_finished(pipeline, recipients) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/pipeline_process_worker.rb b/app/workers/pipeline_process_worker.rb index 83744c5338a..f2aa17acb51 100644 --- a/app/workers/pipeline_process_worker.rb +++ b/app/workers/pipeline_process_worker.rb @@ -6,8 +6,10 @@ class PipelineProcessWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id) Ci::Pipeline.find_by(id: pipeline_id) .try(:process!) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/pipeline_schedule_worker.rb b/app/workers/pipeline_schedule_worker.rb index a1815757735..85d1ffe0fa9 100644 --- a/app/workers/pipeline_schedule_worker.rb +++ b/app/workers/pipeline_schedule_worker.rb @@ -4,6 +4,7 @@ class PipelineScheduleWorker include ApplicationWorker include CronjobQueue + # rubocop: disable CodeReuse/ActiveRecord def perform Ci::PipelineSchedule.active.where("next_run_at < ?", Time.now) .preload(:owner, :project).find_each do |schedule| @@ -21,4 +22,5 @@ class PipelineScheduleWorker end end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/pipeline_success_worker.rb b/app/workers/pipeline_success_worker.rb index 68e9af6a619..4f349ed922c 100644 --- a/app/workers/pipeline_success_worker.rb +++ b/app/workers/pipeline_success_worker.rb @@ -6,6 +6,7 @@ class PipelineSuccessWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id) Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline| MergeRequests::MergeWhenPipelineSucceedsService @@ -13,4 +14,5 @@ class PipelineSuccessWorker .trigger(pipeline) end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/pipeline_update_worker.rb b/app/workers/pipeline_update_worker.rb index c33468c1f14..13a748e1551 100644 --- a/app/workers/pipeline_update_worker.rb +++ b/app/workers/pipeline_update_worker.rb @@ -6,8 +6,10 @@ class PipelineUpdateWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(pipeline_id) Ci::Pipeline.find_by(id: pipeline_id) .try(:update_status) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/process_commit_worker.rb b/app/workers/process_commit_worker.rb index c9f6df9b56d..7b167c95c29 100644 --- a/app/workers/process_commit_worker.rb +++ b/app/workers/process_commit_worker.rb @@ -14,6 +14,7 @@ class ProcessCommitWorker # commit_hash - Hash containing commit details to use for constructing a # Commit object without having to use the Git repository. # default - The data was pushed to the default branch. + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, user_id, commit_hash, default = false) project = Project.find_by(id: project_id) @@ -30,6 +31,7 @@ class ProcessCommitWorker process_commit_message(project, commit, user, author, default) update_issue_metrics(commit, author) end + # rubocop: enable CodeReuse/ActiveRecord def process_commit_message(project, commit, user, author, default = false) # Ignore closing references from GitLab-generated commit messages. @@ -50,6 +52,7 @@ class ProcessCommitWorker end end + # rubocop: disable CodeReuse/ActiveRecord def update_issue_metrics(commit, author) mentioned_issues = commit.all_references(author).issues @@ -58,6 +61,7 @@ class ProcessCommitWorker Issue::Metrics.where(issue_id: mentioned_issues.map(&:id), first_mentioned_in_commit_at: nil) .update_all(first_mentioned_in_commit_at: commit.committed_date) end + # rubocop: enable CodeReuse/ActiveRecord def build_commit(project, hash) date_suffix = '_date' diff --git a/app/workers/project_cache_worker.rb b/app/workers/project_cache_worker.rb index b0e1d8837d9..d27b5e62574 100644 --- a/app/workers/project_cache_worker.rb +++ b/app/workers/project_cache_worker.rb @@ -12,6 +12,7 @@ class ProjectCacheWorker # CHANGELOG. # statistics - An Array containing columns from ProjectStatistics to # refresh, if empty all columns will be refreshed + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, files = [], statistics = []) project = Project.find_by(id: project_id) @@ -23,6 +24,7 @@ class ProjectCacheWorker project.cleanup end + # rubocop: enable CodeReuse/ActiveRecord def update_statistics(project, statistics = []) return unless try_obtain_lease_for(project.id, :update_statistics) diff --git a/app/workers/project_migrate_hashed_storage_worker.rb b/app/workers/project_migrate_hashed_storage_worker.rb index ad0003e7bff..4c6339f7701 100644 --- a/app/workers/project_migrate_hashed_storage_worker.rb +++ b/app/workers/project_migrate_hashed_storage_worker.rb @@ -5,6 +5,7 @@ class ProjectMigrateHashedStorageWorker LEASE_TIMEOUT = 30.seconds.to_i + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, old_disk_path = nil) project = Project.find_by(id: project_id) return if project.nil? || project.pending_delete? @@ -19,6 +20,7 @@ class ProjectMigrateHashedStorageWorker cancel_lease_for(project_id, uuid) if uuid raise ex end + # rubocop: enable CodeReuse/ActiveRecord def lease_for(project_id) Gitlab::ExclusiveLease.new(lease_key(project_id), timeout: LEASE_TIMEOUT) diff --git a/app/workers/project_service_worker.rb b/app/workers/project_service_worker.rb index a0bc9288cf0..25567cec08b 100644 --- a/app/workers/project_service_worker.rb +++ b/app/workers/project_service_worker.rb @@ -7,6 +7,10 @@ class ProjectServiceWorker def perform(hook_id, data) data = data.with_indifferent_access - Service.find(hook_id).execute(data) + service = Service.find(hook_id) + service.execute(data) + rescue => error + service_class = service&.class&.name || "Not Found" + logger.error class: self.class.name, service_class: service_class, message: error.message end end diff --git a/app/workers/propagate_service_template_worker.rb b/app/workers/propagate_service_template_worker.rb index c9da1cae255..3ccd7615697 100644 --- a/app/workers/propagate_service_template_worker.rb +++ b/app/workers/propagate_service_template_worker.rb @@ -6,11 +6,13 @@ class PropagateServiceTemplateWorker LEASE_TIMEOUT = 4.hours.to_i + # rubocop: disable CodeReuse/ActiveRecord def perform(template_id) return unless try_obtain_lease_for(template_id) Projects::PropagateServiceTemplate.propagate(Service.find_by(id: template_id)) end + # rubocop: enable CodeReuse/ActiveRecord private diff --git a/app/workers/prune_old_events_worker.rb b/app/workers/prune_old_events_worker.rb index c1d05ebbcfd..d44ad0d8030 100644 --- a/app/workers/prune_old_events_worker.rb +++ b/app/workers/prune_old_events_worker.rb @@ -4,6 +4,7 @@ class PruneOldEventsWorker include ApplicationWorker include CronjobQueue + # rubocop: disable CodeReuse/ActiveRecord def perform # Contribution calendar shows maximum 12 months of events. # Double nested query is used because MySQL doesn't allow DELETE subqueries @@ -17,4 +18,5 @@ class PruneOldEventsWorker .limit(10_000)) .delete_all end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/prune_web_hook_logs_worker.rb b/app/workers/prune_web_hook_logs_worker.rb index 45c7d32f7eb..38054069f4e 100644 --- a/app/workers/prune_web_hook_logs_worker.rb +++ b/app/workers/prune_web_hook_logs_worker.rb @@ -9,6 +9,7 @@ class PruneWebHookLogsWorker # The maximum number of rows to remove in a single job. DELETE_LIMIT = 50_000 + # rubocop: disable CodeReuse/ActiveRecord def perform # MySQL doesn't allow "DELETE FROM ... WHERE id IN ( ... )" if the inner # query refers to the same table. To work around this we wrap the IN body in @@ -23,4 +24,5 @@ class PruneWebHookLogsWorker ) .delete_all end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/reactive_caching_worker.rb b/app/workers/reactive_caching_worker.rb index 9b331f15dc5..96ff8cd6222 100644 --- a/app/workers/reactive_caching_worker.rb +++ b/app/workers/reactive_caching_worker.rb @@ -3,6 +3,7 @@ class ReactiveCachingWorker include ApplicationWorker + # rubocop: disable CodeReuse/ActiveRecord def perform(class_name, id, *args) klass = begin Kernel.const_get(class_name) @@ -13,4 +14,5 @@ class ReactiveCachingWorker klass.find_by(id: id).try(:exclusively_update_reactive_cache!, *args) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/repository_check/batch_worker.rb b/app/workers/repository_check/batch_worker.rb index 07559ea479b..c1bb1adc9cc 100644 --- a/app/workers/repository_check/batch_worker.rb +++ b/app/workers/repository_check/batch_worker.rb @@ -59,22 +59,28 @@ module RepositoryCheck never_checked_project_ids(BATCH_SIZE) + old_checked_project_ids(BATCH_SIZE) end + # rubocop: disable CodeReuse/ActiveRecord def never_checked_project_ids(batch_size) projects_on_shard.where(last_repository_check_at: nil) .where('created_at < ?', 24.hours.ago) .limit(batch_size).pluck(:id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def old_checked_project_ids(batch_size) projects_on_shard.where.not(last_repository_check_at: nil) .where('last_repository_check_at < ?', 1.month.ago) .reorder(last_repository_check_at: :asc) .limit(batch_size).pluck(:id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def projects_on_shard Project.where(repository_storage: shard_name) end + # rubocop: enable CodeReuse/ActiveRecord def try_obtain_lease_for_project(id) # Use a 24-hour timeout because on servers/projects where 'git fsck' is diff --git a/app/workers/repository_check/clear_worker.rb b/app/workers/repository_check/clear_worker.rb index 81e1a4b63bb..01964c69fb2 100644 --- a/app/workers/repository_check/clear_worker.rb +++ b/app/workers/repository_check/clear_worker.rb @@ -5,6 +5,7 @@ module RepositoryCheck include ApplicationWorker include RepositoryCheckQueue + # rubocop: disable CodeReuse/ActiveRecord def perform # Do small batched updates because these updates will be slow and locking Project.select(:id).find_in_batches(batch_size: 100) do |batch| @@ -14,5 +15,6 @@ module RepositoryCheck ) end end + # rubocop: enable CodeReuse/ActiveRecord end end diff --git a/app/workers/repository_check/single_repository_worker.rb b/app/workers/repository_check/single_repository_worker.rb index f44e5693b25..a8097af321f 100644 --- a/app/workers/repository_check/single_repository_worker.rb +++ b/app/workers/repository_check/single_repository_worker.rb @@ -48,9 +48,11 @@ module RepositoryCheck false end + # rubocop: disable CodeReuse/ActiveRecord def has_changes?(project) Project.with_push.exists?(project.id) end + # rubocop: enable CodeReuse/ActiveRecord def has_wiki_changes?(project) return false unless project.wiki_enabled? diff --git a/app/workers/run_pipeline_schedule_worker.rb b/app/workers/run_pipeline_schedule_worker.rb index 1f6cb18c812..f72331c003a 100644 --- a/app/workers/run_pipeline_schedule_worker.rb +++ b/app/workers/run_pipeline_schedule_worker.rb @@ -6,6 +6,7 @@ class RunPipelineScheduleWorker queue_namespace :pipeline_creation + # rubocop: disable CodeReuse/ActiveRecord def perform(schedule_id, user_id) schedule = Ci::PipelineSchedule.find_by(id: schedule_id) user = User.find_by(id: user_id) @@ -14,6 +15,7 @@ class RunPipelineScheduleWorker run_pipeline_schedule(schedule, user) end + # rubocop: enable CodeReuse/ActiveRecord def run_pipeline_schedule(schedule, user) Ci::CreatePipelineService.new(schedule.project, diff --git a/app/workers/stage_update_worker.rb b/app/workers/stage_update_worker.rb index ec8c8e3689f..ea587789d03 100644 --- a/app/workers/stage_update_worker.rb +++ b/app/workers/stage_update_worker.rb @@ -6,9 +6,11 @@ class StageUpdateWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(stage_id) Ci::Stage.find_by(id: stage_id).try do |stage| stage.update_status end end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/stuck_ci_jobs_worker.rb b/app/workers/stuck_ci_jobs_worker.rb index c78b7fac589..25809f68080 100644 --- a/app/workers/stuck_ci_jobs_worker.rb +++ b/app/workers/stuck_ci_jobs_worker.rb @@ -8,6 +8,7 @@ class StuckCiJobsWorker BUILD_RUNNING_OUTDATED_TIMEOUT = 1.hour BUILD_PENDING_OUTDATED_TIMEOUT = 1.day + BUILD_SCHEDULED_OUTDATED_TIMEOUT = 1.hour BUILD_PENDING_STUCK_TIMEOUT = 1.hour def perform @@ -15,9 +16,10 @@ class StuckCiJobsWorker Rails.logger.info "#{self.class}: Cleaning stuck builds" - drop :running, BUILD_RUNNING_OUTDATED_TIMEOUT - drop :pending, BUILD_PENDING_OUTDATED_TIMEOUT - drop_stuck :pending, BUILD_PENDING_STUCK_TIMEOUT + drop :running, BUILD_RUNNING_OUTDATED_TIMEOUT, 'ci_builds.updated_at < ?', :stuck_or_timeout_failure + drop :pending, BUILD_PENDING_OUTDATED_TIMEOUT, 'ci_builds.updated_at < ?', :stuck_or_timeout_failure + drop :scheduled, BUILD_SCHEDULED_OUTDATED_TIMEOUT, 'scheduled_at IS NOT NULL AND scheduled_at < ?', :stale_schedule + drop_stuck :pending, BUILD_PENDING_STUCK_TIMEOUT, 'ci_builds.updated_at < ?', :stuck_or_timeout_failure remove_lease end @@ -32,24 +34,25 @@ class StuckCiJobsWorker Gitlab::ExclusiveLease.cancel(EXCLUSIVE_LEASE_KEY, @uuid) end - def drop(status, timeout) - search(status, timeout) do |build| - drop_build :outdated, build, status, timeout + def drop(status, timeout, condition, reason) + search(status, timeout, condition) do |build| + drop_build :outdated, build, status, timeout, reason end end - def drop_stuck(status, timeout) - search(status, timeout) do |build| + def drop_stuck(status, timeout, condition, reason) + search(status, timeout, condition) do |build| break unless build.stuck? - drop_build :stuck, build, status, timeout + drop_build :stuck, build, status, timeout, reason end end - def search(status, timeout) + # rubocop: disable CodeReuse/ActiveRecord + def search(status, timeout, condition) loop do jobs = Ci::Build.where(status: status) - .where('ci_builds.updated_at < ?', timeout.ago) + .where(condition, timeout.ago) .includes(:tags, :runner, project: :namespace) .limit(100) .to_a @@ -60,11 +63,12 @@ class StuckCiJobsWorker end end end + # rubocop: enable CodeReuse/ActiveRecord - def drop_build(type, build, status, timeout) - Rails.logger.info "#{self.class}: Dropping #{type} build #{build.id} for runner #{build.runner_id} (status: #{status}, timeout: #{timeout})" + def drop_build(type, build, status, timeout, reason) + Rails.logger.info "#{self.class}: Dropping #{type} build #{build.id} for runner #{build.runner_id} (status: #{status}, timeout: #{timeout}, reason: #{reason})" Gitlab::OptimisticLocking.retry_lock(build, 3) do |b| - b.drop(:stuck_or_timeout_failure) + b.drop(reason) end end end diff --git a/app/workers/stuck_import_jobs_worker.rb b/app/workers/stuck_import_jobs_worker.rb index 79ce06dd66e..de92f3eca6a 100644 --- a/app/workers/stuck_import_jobs_worker.rb +++ b/app/workers/stuck_import_jobs_worker.rb @@ -23,6 +23,7 @@ class StuckImportJobsWorker end.count end + # rubocop: disable CodeReuse/ActiveRecord def mark_projects_with_jid_as_failed! # TODO: Rollback this change to use SQL through #pluck jids_and_ids = enqueued_projects_with_jid.map { |project| [project.import_jid, project.id] }.to_h @@ -43,18 +44,25 @@ class StuckImportJobsWorker project.mark_import_as_failed(error_message) end.count end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def enqueued_projects Project.joins_import_state.where("(import_state.status = 'scheduled' OR import_state.status = 'started') OR (projects.import_status = 'scheduled' OR projects.import_status = 'started')") end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def enqueued_projects_with_jid enqueued_projects.where.not("import_state.jid IS NULL AND projects.import_jid IS NULL") end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def enqueued_projects_without_jid enqueued_projects.where("import_state.jid IS NULL AND projects.import_jid IS NULL") end + # rubocop: enable CodeReuse/ActiveRecord def error_message "Import timed out. Import took longer than #{IMPORT_JOBS_EXPIRATION} seconds" diff --git a/app/workers/stuck_merge_jobs_worker.rb b/app/workers/stuck_merge_jobs_worker.rb index b0a62f76e94..98c81956cba 100644 --- a/app/workers/stuck_merge_jobs_worker.rb +++ b/app/workers/stuck_merge_jobs_worker.rb @@ -4,6 +4,7 @@ class StuckMergeJobsWorker include ApplicationWorker include CronjobQueue + # rubocop: disable CodeReuse/ActiveRecord def perform stuck_merge_requests.find_in_batches(batch_size: 100) do |group| jids = group.map(&:merge_jid) @@ -18,9 +19,11 @@ class StuckMergeJobsWorker end end end + # rubocop: enable CodeReuse/ActiveRecord private + # rubocop: disable CodeReuse/ActiveRecord def apply_current_state!(completed_jids, completed_ids) merge_requests = MergeRequest.where(id: completed_ids) @@ -34,8 +37,11 @@ class StuckMergeJobsWorker Rails.logger.info("Updated state of locked merge jobs. JIDs: #{completed_jids.join(', ')}") end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def stuck_merge_requests MergeRequest.select('id, merge_jid').with_state(:locked).where.not(merge_jid: nil).reorder(nil) end + # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/update_head_pipeline_for_merge_request_worker.rb b/app/workers/update_head_pipeline_for_merge_request_worker.rb index 0487a393566..9ce51662969 100644 --- a/app/workers/update_head_pipeline_for_merge_request_worker.rb +++ b/app/workers/update_head_pipeline_for_merge_request_worker.rb @@ -6,6 +6,7 @@ class UpdateHeadPipelineForMergeRequestWorker queue_namespace :pipeline_processing + # rubocop: disable CodeReuse/ActiveRecord def perform(merge_request_id) merge_request = MergeRequest.find(merge_request_id) pipeline = Ci::Pipeline.where(project: merge_request.source_project, ref: merge_request.source_branch).last @@ -20,6 +21,7 @@ class UpdateHeadPipelineForMergeRequestWorker merge_request.update_attribute(:head_pipeline_id, pipeline.id) end + # rubocop: enable CodeReuse/ActiveRecord def log_error_message_for(merge_request) Rails.logger.error( diff --git a/app/workers/update_merge_requests_worker.rb b/app/workers/update_merge_requests_worker.rb index 742841219b3..c7213df652a 100644 --- a/app/workers/update_merge_requests_worker.rb +++ b/app/workers/update_merge_requests_worker.rb @@ -5,6 +5,7 @@ class UpdateMergeRequestsWorker LOG_TIME_THRESHOLD = 90 # seconds + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, user_id, oldrev, newrev, ref) project = Project.find_by(id: project_id) return unless project @@ -28,4 +29,5 @@ class UpdateMergeRequestsWorker Rails.logger.info("UpdateMergeRequestsWorker#perform #{args_log}") if time.real > LOG_TIME_THRESHOLD end + # rubocop: enable CodeReuse/ActiveRecord end |