Class: Karafka::Pro::ScheduledMessages::MaxEpoch

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/pro/scheduled_messages/max_epoch.rb

Overview

Simple max value accumulator. When we dispatch messages we can store the max timestamp until which messages were dispatched by us. This allows us to quickly skip those messages during recovery, because we do know, they were dispatched.

Instance Method Summary collapse

Constructor Details

#initializeMaxEpoch

Returns a new instance of MaxEpoch.



13
14
15
# File 'lib/karafka/pro/scheduled_messages/max_epoch.rb', line 13

def initialize
  @max = -1
end

Instance Method Details

#to_iInteger

Returns max epoch recorded.

Returns:

  • (Integer)

    max epoch recorded



27
28
29
# File 'lib/karafka/pro/scheduled_messages/max_epoch.rb', line 27

def to_i
  @max
end

#update(new_max) ⇒ Object

Updates epoch if bigger than current max

Parameters:

  • new_max (Integer)

    potential new max epoch



19
20
21
22
23
24
# File 'lib/karafka/pro/scheduled_messages/max_epoch.rb', line 19

def update(new_max)
  return unless new_max
  return unless new_max > @max

  @max = new_max
end