Module: Karafka::Pro::Processing::Strategies::Lrj
- Includes:
- Default
- Defined in:
- lib/karafka/pro/processing/strategies/lrj.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
-
#handle_after_consume ⇒ Object
LRJ standard flow after consumption.
-
#handle_before_enqueue ⇒ Object
We always need to pause prior to doing any jobs for LRJ.
-
#handle_revoked ⇒ Object
We do not un-pause on revokations for LRJ.
Methods included from Default
#handle_before_consume, #handle_consume
Methods included from Karafka::Processing::Strategies::Default
#handle_before_consume, #handle_consume, #handle_shutdown
Methods included from Karafka::Processing::Strategies::Base
#handle_before_consume, #handle_consume, #handle_shutdown
Instance Method Details
#handle_after_consume ⇒ Object
LRJ standard flow after consumption
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/karafka/pro/processing/strategies/lrj.rb', line 45 def handle_after_consume coordinator.on_finished do || if coordinator.success? coordinator.pause_tracker.reset return if coordinator.manual_pause? mark_as_consumed() unless revoked? seek(coordinator.seek_offset) unless revoked? 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_enqueue ⇒ Object
We always need to pause prior to doing any jobs for LRJ
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/karafka/pro/processing/strategies/lrj.rb', line 31 def handle_before_enqueue # 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_revoked ⇒ Object
We do not un-pause on revokations for LRJ
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/karafka/pro/processing/strategies/lrj.rb', line 66 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 |