Class: ActiveJob::Temporal::RetryHandlerExtractor
- Inherits:
-
Object
- Object
- ActiveJob::Temporal::RetryHandlerExtractor
- Defined in:
- lib/activejob/temporal/retry_handler_extractor.rb
Overview
ActiveJob Compatibility ActiveJob does not expose retry_on or discard_on metadata through a public API. If retry metadata cannot be read, the extractor logs a warning and returns nil retry values so RetryMapper can use configured defaults instead of failing during enqueue.
Extracts ActiveJob retry_on and discard_on handler declarations.
This class introspects an ActiveJob class to find all retry_on and discard_on declarations, converting them into structured handler objects. It handles the complexity of ActiveJob’s internal rescue_handlers mechanism, including binding inspection and exception class constantization.
The extractor is used by RetryMapper to separate handler extraction logic from retry policy building logic, improving testability and maintainability.
rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
-
#discard_exception?(job_class, exception) ⇒ Boolean
Checks if an exception should be discarded based on job class handlers.
-
#discard_handlers(job_class) ⇒ Array<Hash>
Extracts discard handler entries from a job class’s rescue_handlers.
-
#initialize ⇒ RetryHandlerExtractor
constructor
A new instance of RetryHandlerExtractor.
-
#retry_handlers(job_class) ⇒ Array<Hash>
Extracts retry handler entries from a job class’s rescue_handlers.
Constructor Details
#initialize ⇒ RetryHandlerExtractor
Returns a new instance of RetryHandlerExtractor.
35 36 37 38 39 |
# File 'lib/activejob/temporal/retry_handler_extractor.rb', line 35 def initialize @cache_mutex = Mutex.new @retry_handlers_by_job_class = ObjectSpace::WeakMap.new @discard_handlers_by_job_class = ObjectSpace::WeakMap.new end |
Instance Method Details
#discard_exception?(job_class, exception) ⇒ Boolean
Checks if an exception should be discarded based on job class handlers.
Inspects the job class’s discard_on declarations to determine if the given exception matches any discard handler. This is used to determine if an activity should raise a non-retryable error in Temporal.
118 119 120 121 122 123 124 |
# File 'lib/activejob/temporal/retry_handler_extractor.rb', line 118 def discard_exception?(job_class, exception) return false unless job_class && exception discard_handlers(job_class).any? do |handler| handles_exception?(handler[:exception], exception) end end |
#discard_handlers(job_class) ⇒ Array<Hash>
Extracts discard handler entries from a job class’s rescue_handlers.
Iterates through the job class’s rescue_handlers and filters for discard_on declarations. Returns structured handler entries with exception classes that should not be retried.
91 92 93 94 95 96 97 |
# File 'lib/activejob/temporal/retry_handler_extractor.rb', line 91 def discard_handlers(job_class) cached_handler_entries(@discard_handlers_by_job_class, job_class) do |handlers| handler_entries(job_class, handlers) do |class_or_name, handler| discard_handler_payload(job_class, class_or_name, handler) end end end |
#retry_handlers(job_class) ⇒ Array<Hash>
Extracts retry handler entries from a job class’s rescue_handlers.
Iterates through the job class’s rescue_handlers and filters for retry_on declarations. Binding metadata is used when available; source-location fallback keeps enqueue working if ActiveJob changes closure locals.
63 64 65 66 67 68 69 |
# File 'lib/activejob/temporal/retry_handler_extractor.rb', line 63 def retry_handlers(job_class) cached_handler_entries(@retry_handlers_by_job_class, job_class) do |handlers| handler_entries(job_class, handlers) do |class_or_name, handler| retry_handler_payload(job_class, class_or_name, handler) end end end |