Class: Kafka::Heartbeat

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka/heartbeat.rb

Instance Method Summary collapse

Constructor Details

#initialize(group:, interval:, instrumenter:) ⇒ Heartbeat

Returns a new instance of Heartbeat.



5
6
7
8
9
10
# File 'lib/kafka/heartbeat.rb', line 5

def initialize(group:, interval:, instrumenter:)
  @group = group
  @interval = interval
  @last_heartbeat = Time.now
  @instrumenter = instrumenter
end

Instance Method Details

#triggerObject



21
22
23
# File 'lib/kafka/heartbeat.rb', line 21

def trigger
  trigger! if Time.now > @last_heartbeat + @interval
end

#trigger!Object



12
13
14
15
16
17
18
19
# File 'lib/kafka/heartbeat.rb', line 12

def trigger!
  @instrumenter.instrument('heartbeat.consumer',
                           group_id: @group.group_id,
                           topic_partitions: @group.assigned_partitions) do
    @group.heartbeat
    @last_heartbeat = Time.now
  end
end