Sha256: bf54811b144069089d5c1acad70a00b7a32f6c610a58b388b854453aeac8f5df

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 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
            pause(coordinator.seek_offset, nil, false)
          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

1 entries across 1 versions & 1 rubygems

Version Path
karafka-2.0.23 lib/karafka/processing/strategies/aj_dlq_mom.rb