Class: Philiprehberger::RetryQueue::Processor
- Inherits:
-
Object
- Object
- Philiprehberger::RetryQueue::Processor
- Defined in:
- lib/philiprehberger/retry_queue/processor.rb
Overview
Processes items with per-item retry, backoff, and dead letter collection.
Constant Summary collapse
- DEFAULT_BACKOFF =
Default backoff strategy: exponential with base 0.1s.
->(attempt) { 0.1 * (2**attempt) }
Instance Method Summary collapse
-
#call(items) {|item| ... } ⇒ Result
Process a collection of items with retry logic.
-
#initialize(max_retries: 3, concurrency: 1, backoff: nil, retry_on: nil, on_retry: nil, on_failure: nil) ⇒ Processor
constructor
A new instance of Processor.
Constructor Details
#initialize(max_retries: 3, concurrency: 1, backoff: nil, retry_on: nil, on_retry: nil, on_failure: nil) ⇒ Processor
Returns a new instance of Processor.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/philiprehberger/retry_queue/processor.rb', line 18 def initialize(max_retries: 3, concurrency: 1, backoff: nil, retry_on: nil, on_retry: nil, on_failure: nil) raise Error, 'max_retries must be non-negative' unless max_retries.is_a?(Integer) && max_retries >= 0 @max_retries = max_retries @concurrency = concurrency @backoff = backoff || DEFAULT_BACKOFF @retry_on = retry_on @on_retry_hooks = Array(on_retry) @on_failure = on_failure end |
Instance Method Details
#call(items) {|item| ... } ⇒ Result
Process a collection of items with retry logic.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/philiprehberger/retry_queue/processor.rb', line 34 def call(items, &block) raise Error, 'a processing block is required' unless block succeeded = [] failed = [] start_time = now items.each do |item| process_item(item, succeeded, failed, &block) end Result.new(succeeded: succeeded, failed: failed, elapsed: now - start_time) end |