You need to sign in or sign up before continuing.
Add cop to avoid find in Sidekiq workers
What does this MR do and why?
Related to #472036 (closed)
This introduces a new Rubocop to avoid use of find
in Sidekiq workers
Why
Sidekiq workers that run on records that are deleted will fail and retry many times due to how Sidekiq retries work. It's recommended to use find_by
in the documentation, but we should surface that recommendation to developers in the IDE.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
N/A
How to set up and validate locally
- create or modify a sidekiq worker to use
find
method - run rubocop on the worker
➜ rubocop ee/app/workers/search/zoekt/namespace_indexer_worker.rb
Inspecting 1 file
C
Offenses:
ee/app/workers/search/zoekt/namespace_indexer_worker.rb:13:32: C: Style/InlineDisableAnnotation: Inline disabling a cop needs to follow the format of # rubocop:disable SidekiqLoadBalancing/WorkerDataConsistency -- Some reason.
See https://docs.gitlab.com/ee/development/rubocop_development_guide.html#disabling-rules-inline.
data_consistency :always # rubocop:disable SidekiqLoadBalancing/WorkerDataConsistency
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ee/app/workers/search/zoekt/namespace_indexer_worker.rb:21:21: C: Sidekiq/AvoidFindInSidekiqWorkers: Refrain from using find, use find_by instead.
A job should not fail when the record it was scheduled for is deleted.
See https://docs.gitlab.com/ee/development/sidekiq/#retries.
namespace = Namespace.find(namespace_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 file inspected, 2 offenses detected
Edited by Terri Chu