Sha256: 1ae6323cf95e6f27140bd20b3ef6b3d9f6ecfca4f52c6f2eebd2ff3d140e9e14

Contents?: true

Size: 1.52 KB

Versions: 14

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Karafka
  module Processing
    module Strategies
      # ActiveJob strategy to cooperate with the DLQ.
      #
      # While AJ is uses MOM by default because it delegates the offset management to the AJ
      # consumer. With DLQ however there is an extra case for skipping broken jobs with offset
      # marking due to ordered processing.
      module AjDlqMom
        include DlqMom

        # Apply strategy when only when using AJ with MOM and DLQ
        FEATURES = %i[
          active_job
          dead_letter_queue
          manual_offset_management
        ].freeze

        # How should we post-finalize consumption.
        def handle_after_consume
          return if revoked?

          if coordinator.success?
            # Do NOT commit offsets, they are comitted after each job in the AJ consumer.
            coordinator.pause_tracker.reset
          elsif coordinator.pause_tracker.attempt <= topic.dead_letter_queue.max_retries
            retry_after_pause
          else
            coordinator.pause_tracker.reset
            skippable_message = find_skippable_message
            dispatch_to_dlq(skippable_message)
            # We can commit the offset here because we know that we skip it "forever" and
            # since AJ consumer commits the offset after each job, we also know that the
            # previous job was successful
            mark_as_consumed(skippable_message)
            pause(coordinator.seek_offset, nil, false)
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
karafka-2.0.38 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.37 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.36 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.35 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.34 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.33 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.32 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.31 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.30 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.29 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.28 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.27 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.26 lib/karafka/processing/strategies/aj_dlq_mom.rb
karafka-2.0.24 lib/karafka/processing/strategies/aj_dlq_mom.rb