Class: Karafka::Pro::ScheduledMessages::MaxEpoch
- Inherits:
-
Object
- Object
- Karafka::Pro::ScheduledMessages::MaxEpoch
- 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
-
#to_i ⇒ Integer
readonly
Max epoch recorded.
Instance Method Summary collapse
-
#initialize ⇒ MaxEpoch
constructor
Initializes max epoch tracker with -1 as starting value.
-
#update(new_max) ⇒ Object
Updates epoch if bigger than current max.
Constructor Details
#initialize ⇒ MaxEpoch
Initializes max epoch tracker with -1 as starting value
27 28 29 30 |
# File 'lib/karafka/pro/scheduled_messages/max_epoch.rb', line 27 def initialize @max = -1 @to_i = @max end |
Instance Attribute Details
#to_i ⇒ Integer (readonly)
Returns max epoch recorded.
24 25 26 |
# File 'lib/karafka/pro/scheduled_messages/max_epoch.rb', line 24 def to_i @to_i end |
Instance Method Details
#update(new_max) ⇒ Object
Updates epoch if bigger than current max
34 35 36 37 38 39 |
# File 'lib/karafka/pro/scheduled_messages/max_epoch.rb', line 34 def update(new_max) return unless new_max > @max @max = new_max @to_i = @max - GRACE_PERIOD end |