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.6.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, jitter: 0.0) {|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. Note: max_retries: 0 means one attempt with no retries (not zero attempts); the item is processed once and moves straight to the dead-letter list on failure.

  • 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

  • jitter (Numeric) (defaults to: 0.0) —

    fraction in 0.0..1.0 applied to the computed backoff delay as delay * (1 + rand * jitter) to reduce thundering-herd risk. Defaults to 0.0 (no jitter).

Yields:

  • (item) —

    block that processes a single item

Returns:

  • (Result) —

    processing result



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/philiprehberger/retry_queue.rb', line 28

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