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.



30
31
32
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 30

def initialize
  @errors = []
end

Instance Method Details

#<<(error) ⇒ Object

Parameters:

  • error (StandardError)

    adds the error to the tracker



40
41
42
43
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 40

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



67
68
69
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 67

def all
  @errors
end

#clearObject

Clears all the errors



35
36
37
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 35

def clear
  @errors.clear
end

#each(&block) ⇒ Object

Iterates over errors

Parameters:

  • block (Proc)

    code we want to run on each error



62
63
64
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 62

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

#empty?Boolean

Returns is the error tracker empty.

Returns:

  • (Boolean)

    is the error tracker empty



46
47
48
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 46

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



56
57
58
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 56

def last
  @errors.last
end

#sizeInteger

Returns number of elements.

Returns:

  • (Integer)

    number of elements



51
52
53
# File 'lib/karafka/pro/processing/coordinators/errors_tracker.rb', line 51

def size
  count
end