Class: Karafka::Pro::Processing::Coordinators::ErrorsTracker

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/karafka/pro/processing/coordinators/errors_tracker.rb

Overview

Object used to track errors in between executions to be able to build error-type based recovery flows.

Instance Method Summary collapse

Constructor Details

#initializeErrorsTracker

Returns a new instance of ErrorsTracker.



22
23
24
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 22

def initialize
  @errors = []
end

Instance Method Details

#<<(error) ⇒ Object

Parameters:

  • error (StandardError)

    adds the error to the tracker



32
33
34
35
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 32

def <<(error)
  @errors.shift if @errors.size >= STORAGE_LIMIT
  @errors << error
end

#allArray<StandardError>

Returns array with all the errors that occurred.

Returns:

  • (Array<StandardError>)

    array with all the errors that occurred



59
60
61
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 59

def all
  @errors
end

#clearObject

Clears all the errors



27
28
29
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 27

def clear
  @errors.clear
end

#each(&block) ⇒ Object

Iterates over errors

Parameters:

  • block (Proc)

    code we want to run on each error



54
55
56
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 54

def each(&block)
  @errors.each(&block)
end

#empty?Boolean

Returns is the error tracker empty.

Returns:

  • (Boolean)

    is the error tracker empty



38
39
40
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 38

def empty?
  @errors.empty?
end

#lastStandardError?

Returns last error that occurred or nil if no errors.

Returns:

  • (StandardError, nil)

    last error that occurred or nil if no errors



48
49
50
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 48

def last
  @errors.last
end

#sizeInteger

Returns number of elements.

Returns:

  • (Integer)

    number of elements



43
44
45
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 43

def size
  count
end