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

Initializes the result as successful with no cause



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

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



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

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

#failure?Boolean

Returns true if processing failed.

Returns:

  • (Boolean)

    true if processing failed



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

def failure?
  !@success
end

#success!Object

Marks state as successful



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

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)


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

def success?
  @success
end