Class: Philiprehberger::RetryQueue::Result
- Inherits:
-
Object
- Object
- Philiprehberger::RetryQueue::Result
- Defined in:
- lib/philiprehberger/retry_queue/result.rb
Overview
Holds the outcome of a batch processing run.
Instance Attribute Summary collapse
-
#failed ⇒ Array<Hash>
readonly
Items that exhausted retries, each with :item, :error, :attempts.
-
#succeeded ⇒ Array
readonly
Items that were processed successfully.
Instance Method Summary collapse
-
#initialize(succeeded:, failed:, elapsed:) ⇒ Result
constructor
A new instance of Result.
-
#reprocess_failed {|item, error| ... } ⇒ Result
Reprocess failed items by yielding each item and its last error to the block.
-
#stats ⇒ Hash
Return processing statistics.
Constructor Details
#initialize(succeeded:, failed:, elapsed:) ⇒ Result
Returns a new instance of Result.
16 17 18 19 20 |
# File 'lib/philiprehberger/retry_queue/result.rb', line 16 def initialize(succeeded:, failed:, elapsed:) @succeeded = succeeded @failed = failed @elapsed = elapsed end |
Instance Attribute Details
#failed ⇒ Array<Hash> (readonly)
Returns items that exhausted retries, each with :item, :error, :attempts.
11 12 13 |
# File 'lib/philiprehberger/retry_queue/result.rb', line 11 def failed @failed end |
#succeeded ⇒ Array (readonly)
Returns items that were processed successfully.
8 9 10 |
# File 'lib/philiprehberger/retry_queue/result.rb', line 8 def succeeded @succeeded end |
Instance Method Details
#reprocess_failed {|item, error| ... } ⇒ Result
Reprocess failed items by yielding each item and its last error to the block. Returns a new Result with the reprocessing outcomes.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/philiprehberger/retry_queue/result.rb', line 41 def reprocess_failed(&block) raise Error, 'a reprocessing block is required' unless block reprocess_succeeded = [] reprocess_failed = [] start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) @failed.each do |entry| block.call(entry[:item], entry[:error]) reprocess_succeeded << entry[:item] rescue StandardError => e reprocess_failed << { item: entry[:item], error: e, attempts: 1 } end elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time Result.new(succeeded: reprocess_succeeded, failed: reprocess_failed, elapsed: elapsed) end |
#stats ⇒ Hash
Return processing statistics.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/philiprehberger/retry_queue/result.rb', line 25 def stats total = @succeeded.size + @failed.size { total: total, succeeded: @succeeded.size, failed: @failed.size, success_rate: total.zero? ? 0.0 : @succeeded.size.to_f / total, elapsed: @elapsed } end |