Class: Karafka::Pro::ScheduledMessages::State

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

Overview

Represents the loading/bootstrapping state of the given topic partition

Bootstrapping can be in the following states: - fresh - when we got an assignment but we did not load the schedule yet - loading - when we are in the process of bootstrapping the daily state and we consume historical messages to build the needed schedules. - loaded - state in which we finished loading all the schedules and we can dispatch messages when the time comes and we can process real-time incoming schedules and changes to schedules as they appear in the stream.

Instance Method Summary collapse

Constructor Details

#initialize(loaded = nil) ⇒ State

Returns a new instance of State.

Parameters:

  • loaded (nil, false, true) (defaults to: nil)

    is the state loaded or not yet. nil indicates, it is a fresh, pre-seek state.



21
22
23
# File 'lib/karafka/pro/scheduled_messages/state.rb', line 21

def initialize(loaded = nil)
  @loaded = loaded
end

Instance Method Details

#fresh?Boolean

Returns are we in a fresh, pre-bootstrap state.

Returns:

  • (Boolean)

    are we in a fresh, pre-bootstrap state



26
27
28
# File 'lib/karafka/pro/scheduled_messages/state.rb', line 26

def fresh?
  @loaded.nil?
end

#loaded!Object

Marks the current state as fully loaded



31
32
33
# File 'lib/karafka/pro/scheduled_messages/state.rb', line 31

def loaded!
  @loaded = true
end

#loaded?Boolean

Returns are we in a loaded state.

Returns:

  • (Boolean)

    are we in a loaded state



36
37
38
# File 'lib/karafka/pro/scheduled_messages/state.rb', line 36

def loaded?
  @loaded == true
end

#to_sString

Returns current state string representation.

Returns:

  • (String)

    current state string representation



41
42
43
44
45
46
47
48
49
50
# File 'lib/karafka/pro/scheduled_messages/state.rb', line 41

def to_s
  case @loaded
  when nil
    'fresh'
  when false
    'loading'
  when true
    'loaded'
  end
end