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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMaxEpoch

Initializes max epoch tracker with -1 as starting value



52
53
54
55
# File 'lib/karafka/pro/scheduled_messages/max_epoch.rb', line 52

def initialize
  @max = -1
  @to_i = @max
end

Instance Attribute Details

#to_iInteger (readonly)

Returns max epoch recorded.

Returns:

  • (Integer)

    max epoch recorded



49
50
51
# File 'lib/karafka/pro/scheduled_messages/max_epoch.rb', line 49

def to_i
  @to_i
end

Instance Method Details

#update(new_max) ⇒ Object

Updates epoch if bigger than current max

Parameters:

  • new_max (Integer)

    potential new max epoch



59
60
61
62
63
64
# File 'lib/karafka/pro/scheduled_messages/max_epoch.rb', line 59

def update(new_max)
  return unless new_max > @max

  @max = new_max
  @to_i = @max - GRACE_PERIOD
end