Class: WaterDrop::Producer::Status
- Inherits:
-
Object
- Object
- WaterDrop::Producer::Status
- Defined in:
- lib/waterdrop/producer/status.rb
Overview
Producer lifecycle status object representation
Constant Summary collapse
- ACTIVE_STATES =
States in which the producer is considered active and able to accept work. Kept as a single set so the current state can be classified in one atomic read (see ‘#active?` / `#to_sym`) rather than via a chain of predicate calls that could straddle a concurrent transition.
%i[ connected configured disconnecting disconnected ].freeze
Instance Method Summary collapse
-
#active? ⇒ Boolean
True if producer is in a active state.
-
#initialize ⇒ Status
constructor
Creates a new instance of status with the initial state.
-
#to_s ⇒ String
Current status as a string.
-
#to_sym ⇒ Symbol
Current lifecycle state captured as a single atomic read.
Constructor Details
#initialize ⇒ Status
Creates a new instance of status with the initial state
32 33 34 |
# File 'lib/waterdrop/producer/status.rb', line 32 def initialize @current = LIFECYCLE.first end |
Instance Method Details
#active? ⇒ Boolean
Returns true if producer is in a active state. Active means, that we can start sending messages. Active states are connected (connection established), configured which means, that producer is configured, but connection with Kafka is not yet established or disconnected, meaning it was working but user disconnected for his own reasons though sending could reconnect and continue.
41 42 43 44 45 46 |
# File 'lib/waterdrop/producer/status.rb', line 41 def active? # Single read of @current so a concurrent transition cannot make this return false for a # status that is in fact active (for example flipping configured -> connected mid-check # while another thread reloads the client after a fatal error). ACTIVE_STATES.include?(@current) end |
#to_s ⇒ String
Returns current status as a string.
49 50 51 |
# File 'lib/waterdrop/producer/status.rb', line 49 def to_s @current.to_s end |
#to_sym ⇒ Symbol
Returns current lifecycle state captured as a single atomic read. Lets callers branch on one consistent value instead of issuing several predicate calls that could observe different states if the producer is transitioning on another thread.
56 57 58 |
# File 'lib/waterdrop/producer/status.rb', line 56 def to_sym @current end |