Sha256: eb0dfc05706e79470564876dafef63fc0584a2914feaf53fe56691c42f8c81dd

Contents?: true

Size: 1.22 KB

Versions: 55

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module Karafka
  module Messages
    # Simple batch metadata object that stores all non-message information received from Kafka
    # cluster while fetching the data.
    #
    # @note This metadata object refers to per batch metadata, not `#message.metadata`
    BatchMetadata = Struct.new(
      :size,
      :first_offset,
      :last_offset,
      :deserializer,
      :partition,
      :topic,
      :created_at,
      :scheduled_at,
      :processed_at,
      keyword_init: true
    ) do
      # This lag describes how long did it take for a message to be consumed from the moment it was
      # created
      def consumption_lag
        time_distance_in_ms(processed_at, created_at)
      end

      # This lag describes how long did a batch have to wait before it was picked up by one of the
      # workers
      def processing_lag
        time_distance_in_ms(processed_at, scheduled_at)
      end

      private

      # Computes time distance in between two times in ms
      #
      # @param time1 [Time]
      # @param time2 [Time]
      # @return [Integer] distance in between two times in ms
      def time_distance_in_ms(time1, time2)
        ((time1 - time2) * 1_000).round
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
karafka-2.1.3 lib/karafka/messages/batch_metadata.rb
karafka-2.1.2 lib/karafka/messages/batch_metadata.rb
karafka-2.1.1 lib/karafka/messages/batch_metadata.rb
karafka-2.1.0 lib/karafka/messages/batch_metadata.rb
karafka-2.0.41 lib/karafka/messages/batch_metadata.rb
karafka-2.0.40 lib/karafka/messages/batch_metadata.rb
karafka-2.0.39 lib/karafka/messages/batch_metadata.rb
karafka-2.0.38 lib/karafka/messages/batch_metadata.rb
karafka-2.0.37 lib/karafka/messages/batch_metadata.rb
karafka-2.0.36 lib/karafka/messages/batch_metadata.rb
karafka-2.0.35 lib/karafka/messages/batch_metadata.rb
karafka-2.0.34 lib/karafka/messages/batch_metadata.rb
karafka-2.0.33 lib/karafka/messages/batch_metadata.rb
karafka-2.0.32 lib/karafka/messages/batch_metadata.rb
karafka-2.0.31 lib/karafka/messages/batch_metadata.rb
karafka-2.0.30 lib/karafka/messages/batch_metadata.rb
karafka-2.0.29 lib/karafka/messages/batch_metadata.rb
karafka-2.0.28 lib/karafka/messages/batch_metadata.rb
karafka-2.0.27 lib/karafka/messages/batch_metadata.rb
karafka-2.0.26 lib/karafka/messages/batch_metadata.rb