Class: Karafka::Processing::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/processing/result.rb

Overview

A simple object that allows us to keep track of processing state. It allows to indicate if given thing moved from success to a failure or the other way around Useful for tracking consumption state

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResult

Returns a new instance of Result.



11
12
13
14
# File 'lib/karafka/processing/result.rb', line 11

def initialize
  @success = true
  @cause = false
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



9
10
11
# File 'lib/karafka/processing/result.rb', line 9

def cause
  @cause
end

Instance Method Details

#failure!(cause) ⇒ Object

Marks state as failure

Parameters:

  • cause (StandardError)

    error that occurred and caused failure



31
32
33
34
# File 'lib/karafka/processing/result.rb', line 31

def failure!(cause)
  @success = false
  @cause = cause
end

#failure?Boolean

Returns true if processing failed.

Returns:

  • (Boolean)

    true if processing failed



37
38
39
# File 'lib/karafka/processing/result.rb', line 37

def failure?
  !@success
end

#success!Object

Marks state as successful



22
23
24
25
26
27
# File 'lib/karafka/processing/result.rb', line 22

def success!
  @success = true
  # We set cause to false so the previous error that occurred does not leak when error is
  # no longer present
  @cause = false
end

#success?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/karafka/processing/result.rb', line 17

def success?
  @success
end