Module: Philiprehberger::RetryQueue

Defined in:
lib/philiprehberger/retry_queue.rb,
lib/philiprehberger/retry_queue/result.rb,
lib/philiprehberger/retry_queue/version.rb,
lib/philiprehberger/retry_queue/processor.rb

Defined Under Namespace

Classes: Error, Processor, Result

Constant Summary collapse

VERSION =
'0.3.0'

Class Method Summary collapse

Class Method Details

.process(items, max_retries: 3, concurrency: 1, backoff: nil, retry_on: nil, on_retry: nil, on_failure: nil) {|item| ... } ⇒ Result

Process items with per-item retry, backoff, and dead letter collection.

Parameters:

  • items (Array)

    items to process

  • max_retries (Integer) (defaults to: 3)

    maximum retry attempts per item

  • concurrency (Integer) (defaults to: 1)

    number of concurrent workers

  • backoff (Proc, nil) (defaults to: nil)

    custom backoff strategy

  • retry_on (Array<Class>, nil) (defaults to: nil)

    exception classes to retry on; others go straight to failed

  • on_retry (Array<Proc>, nil) (defaults to: nil)

    callbacks fired before each retry attempt

  • on_failure (Proc, nil) (defaults to: nil)

    callable invoked with ‘(item, error)` once per item that exhausts retries and moves to the dead-letter list; exceptions raised by the hook are swallowed so a faulty hook cannot break the queue

Yields:

  • (item)

    block that processes a single item

Returns:

  • (Result)

    processing result



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/philiprehberger/retry_queue.rb', line 24

def self.process(items, max_retries: 3, concurrency: 1, backoff: nil, retry_on: nil, on_retry: nil,
                 on_failure: nil, &block)
  processor = Processor.new(
    max_retries: max_retries,
    concurrency: concurrency,
    backoff: backoff,
    retry_on: retry_on,
    on_retry: on_retry,
    on_failure: on_failure
  )
  processor.call(items, &block)
end