diff options
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/sidekiq_load_balancing/worker_data_consistency.rb | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/rubocop/cop/sidekiq_load_balancing/worker_data_consistency.rb b/rubocop/cop/sidekiq_load_balancing/worker_data_consistency.rb index 7fe308d6b40..badd81ff138 100644 --- a/rubocop/cop/sidekiq_load_balancing/worker_data_consistency.rb +++ b/rubocop/cop/sidekiq_load_balancing/worker_data_consistency.rb @@ -28,36 +28,29 @@ module RuboCop HELP_LINK = 'https://docs.gitlab.com/ee/development/sidekiq/worker_attributes.html#job-data-consistency-strategies' - MSG = <<~MSG + MISSING_DATA_CONSISTENCY_MSG = <<~MSG Should define data_consistency expectation. - - It is encouraged for workers to use database replicas as much as possible by declaring - data_consistency to use the :delayed or :sticky modes. Mode :always will result in the - worker always hitting the primary database node for both reads and writes, which limits - scalability. - - Some guidelines: - - 1. If your worker mostly writes or reads its own writes, use mode :always. TRY TO AVOID THIS. - 2. If your worker performs mostly reads and can tolerate small delays, use mode :delayed. - 3. If your worker performs mostly reads but cannot tolerate any delays, use mode :sticky. - See #{HELP_LINK} for a more detailed explanation of these settings. MSG + DISCOURAGE_ALWAYS_MSG = "Refrain from using `:always` if possible." \ + "See #{HELP_LINK} for a more detailed explanation of these settings." + def_node_search :application_worker?, <<~PATTERN `(send nil? :include (const nil? :ApplicationWorker)) PATTERN - def_node_search :data_consistency_defined?, <<~PATTERN - `(send nil? :data_consistency ...) + def_node_matcher :data_consistency_value, <<~PATTERN + `(send nil? :data_consistency $(sym _) ...) PATTERN def on_class(node) - return unless in_worker?(node) && application_worker?(node) - return if data_consistency_defined?(node) + return unless application_worker?(node) + + consistency = data_consistency_value(node) + return add_offense(node, message: MISSING_DATA_CONSISTENCY_MSG) if consistency.nil? - add_offense(node) + add_offense(consistency, message: DISCOURAGE_ALWAYS_MSG) if consistency.value == :always end end end |