Sha256: daea11bdc9522c92809c28cd2eeb91c0b2e2c393af8f49de0059b53f91d03597

Contents?: true

Size: 1.53 KB

Versions: 35

Compression:

Stored size: 1.53 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
      #
      #
      # @return [Integer] number of milliseconds
      # @note In case of usage in workless flows, this value will be set to -1
      def consumption_lag
        processed_at ? time_distance_in_ms(processed_at, created_at) : -1
      end

      # This lag describes how long did a batch have to wait before it was picked up by one of the
      # workers
      #
      # @return [Integer] number of milliseconds
      # @note In case of usage in workless flows, this value will be set to -1
      def processing_lag
        processed_at ? time_distance_in_ms(processed_at, scheduled_at) : -1
      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

35 entries across 35 versions & 1 rubygems

Version Path
karafka-2.3.4 lib/karafka/messages/batch_metadata.rb
karafka-2.3.3 lib/karafka/messages/batch_metadata.rb
karafka-2.3.2 lib/karafka/messages/batch_metadata.rb
karafka-2.3.1 lib/karafka/messages/batch_metadata.rb
karafka-2.3.0 lib/karafka/messages/batch_metadata.rb
karafka-2.3.0.rc1 lib/karafka/messages/batch_metadata.rb
karafka-2.3.0.alpha2 lib/karafka/messages/batch_metadata.rb
karafka-2.3.0.alpha1 lib/karafka/messages/batch_metadata.rb
karafka-2.2.14 lib/karafka/messages/batch_metadata.rb
karafka-2.2.13 lib/karafka/messages/batch_metadata.rb
karafka-2.2.12 lib/karafka/messages/batch_metadata.rb
karafka-2.2.11 lib/karafka/messages/batch_metadata.rb
karafka-2.2.10 lib/karafka/messages/batch_metadata.rb
karafka-2.2.9 lib/karafka/messages/batch_metadata.rb
karafka-2.2.8 lib/karafka/messages/batch_metadata.rb
karafka-2.2.8.beta1 lib/karafka/messages/batch_metadata.rb
karafka-2.2.7 lib/karafka/messages/batch_metadata.rb
karafka-2.2.6 lib/karafka/messages/batch_metadata.rb
karafka-2.2.5 lib/karafka/messages/batch_metadata.rb
karafka-2.2.4 lib/karafka/messages/batch_metadata.rb