Class: Phobos::Actions::ProcessBatch

Inherits:
Object
  • Object
show all
Includes:
Instrumentation, Log
Defined in:
lib/phobos/actions/process_batch.rb

Constant Summary

Constants included from Instrumentation

Instrumentation::NAMESPACE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

#log_debug, #log_error, #log_info, #log_warn

Methods included from Instrumentation

#instrument, subscribe, unsubscribe

Constructor Details

#initialize(listener:, batch:, listener_metadata:) ⇒ ProcessBatch

Returns a new instance of ProcessBatch.



11
12
13
14
15
16
17
18
19
20
# File 'lib/phobos/actions/process_batch.rb', line 11

def initialize(listener:, batch:, listener_metadata:)
  @listener = listener
  @batch = batch
  @listener_metadata = 
  @metadata = .merge(
    batch_size: batch.messages.count,
    partition: batch.partition,
    offset_lag: batch.offset_lag
  )
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



9
10
11
# File 'lib/phobos/actions/process_batch.rb', line 9

def 
  @metadata
end

Instance Method Details

#executeObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/phobos/actions/process_batch.rb', line 22

def execute
  instrument('listener.process_batch', @metadata) do ||
    @batch.messages.each do |message|
      Phobos::Actions::ProcessMessage.new(
        listener: @listener,
        message: message,
        listener_metadata: @listener_metadata
      ).execute
      begin
        @listener.consumer.trigger_heartbeat
      rescue Kafka::HeartbeatError => e
        log_warn("Error sending Heartbeat #{e.class.name}-#{e}")
      end
    end
  end
end