Module: Karafka::Pro::Processing::Strategies::Lrj::Default

Includes:
Default
Included in:
Dlq::Lrj, Ftr, Vp
Defined in:
lib/karafka/pro/processing/strategies/lrj/default.rb

Overview

Long-Running Job enabled

Constant Summary collapse

MAX_PAUSE_TIME =

Pause for tops 31 years

1_000_000_000_000
FEATURES =

Features for this strategy

%i[
  long_running_job
].freeze

Instance Method Summary collapse

Methods included from Default

#handle_before_consume, #handle_consume

Methods included from Karafka::Processing::Strategies::Default

#commit_offsets, #commit_offsets!, #handle_before_consume, #handle_consume, #handle_idle, #handle_shutdown, #mark_as_consumed, #mark_as_consumed!

Methods included from Karafka::Processing::Strategies::Base

#handle_before_consume, #handle_consume, #handle_idle, #handle_shutdown

Instance Method Details

#handle_after_consumeObject

LRJ standard flow after consumption



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/karafka/pro/processing/strategies/lrj/default.rb', line 48

def handle_after_consume
  coordinator.on_finished do |last_group_message|
    if coordinator.success?
      coordinator.pause_tracker.reset

      return if coordinator.manual_pause?

      mark_as_consumed(last_group_message) unless revoked?
      seek(coordinator.seek_offset, false) unless revoked? || coordinator.manual_seek?

      resume
    else
      # If processing failed, we need to pause
      # For long running job this will overwrite the default never-ending pause and
      # will cause the processing to keep going after the error backoff
      retry_after_pause
    end
  end
end

#handle_before_enqueueObject

We always need to pause prior to doing any jobs for LRJ



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/karafka/pro/processing/strategies/lrj/default.rb', line 32

def handle_before_enqueue
  super

  # This ensures that when running LRJ with VP, things operate as expected run only
  # once for all the virtual partitions collectively
  coordinator.on_enqueued do
    # Pause at the first message in a batch. That way in case of a crash, we will not
    # loose any messages.
    #
    # For VP it applies the same way and since VP cannot be used with MOM we should not
    # have any edge cases here.
    pause(coordinator.seek_offset, MAX_PAUSE_TIME, false)
  end
end

#handle_revokedObject

We do not un-pause on revokations for LRJ



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/karafka/pro/processing/strategies/lrj/default.rb', line 69

def handle_revoked
  coordinator.on_revoked do
    # We do not want to resume on revocation in case of a LRJ.
    # For LRJ we resume after the successful processing or do a backoff pause in case
    # of a failure. Double non-blocking resume could cause problems in coordination.
    coordinator.revoke
  end

  Karafka.monitor.instrument('consumer.revoke', caller: self)
  Karafka.monitor.instrument('consumer.revoked', caller: self) do
    revoked
  end
end