Class: Pgbus::Process::Dispatcher::LoopOutcome

Inherits:
Object
  • Object
show all
Defined in:
lib/pgbus/process/dispatcher.rb

Overview

Accumulates the per-item outcomes of a task that loops over queues. A task should only be considered failed when it attempted work and every attempt failed — a partial failure (some items succeed) must not trip maintenance backoff. #result returns the first error in the total-failure case and nil otherwise, matching the "return e on failure" contract run_if_due expects.

Instance Method Summary collapse

Constructor Details

#initializeLoopOutcome

Returns a new instance of LoopOutcome.



74
75
76
77
78
# File 'lib/pgbus/process/dispatcher.rb', line 74

def initialize
  @successes = 0
  @failures = 0
  @first_error = nil
end

Instance Method Details

#record_failure(error) ⇒ Object



84
85
86
87
# File 'lib/pgbus/process/dispatcher.rb', line 84

def record_failure(error)
  @failures += 1
  @first_error = error if @first_error.nil?
end

#record_successObject



80
81
82
# File 'lib/pgbus/process/dispatcher.rb', line 80

def record_success
  @successes += 1
end

#resultObject



89
90
91
# File 'lib/pgbus/process/dispatcher.rb', line 89

def result
  @first_error if @failures.positive? && @successes.zero?
end