Class: RuboCop::Cop::Sequra::AsyncJobPattern
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Sequra::AsyncJobPattern
- Defined in:
- lib/rubocop/cop/sequra/async_job_pattern.rb
Overview
Detects Sidekiq jobs that haven’t adopted the ApplicationOperation pattern.
A job is considered migrated when it meets ALL conditions:
-
Has exactly ONE ‘*Operation.call` invocation (delegates to single operation)
-
Class length ≤ 10 “smart lines” (using CountAsOne semantics)
A job is considered unmigrated (offense) when:
-
Zero ‘Operation.call` → business logic lives in the job itself
-
Multiple ‘Operation.call` → job orchestrates multiple operations
-
Exceeds class length → job has too much logic beyond delegation
Constant Summary collapse
- MSG =
"Sidekiq job should delegate to exactly one Operation".freeze
- MSG_CLASS_LENGTH =
"Job has too much logic to be a simple Operation delegate. " \ "Consider moving logic into the Operation".freeze
- MAX_CLASS_LENGTH =
10- COUNT_AS_ONE =
["array", "hash", "heredoc", "method_call"].freeze
- OPERATION_CLASS_PATTERN =
/Operation$/
Instance Method Summary collapse
Instance Method Details
#on_class(node) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/rubocop/cop/sequra/async_job_pattern.rb', line 68 def on_class(node) return unless sidekiq_job?(node) check_operation_delegation(node) check_class_length(node) end |