Class: EventSourcery::Memory::Tracker
- Inherits:
-
Object
- Object
- EventSourcery::Memory::Tracker
- Defined in:
- lib/event_sourcery/memory/tracker.rb
Overview
Being able to know where you’re at when reading an event stream is important. In here are mechanisms to do so.
Instance Method Summary collapse
-
#initialize ⇒ Tracker
constructor
Tracking where you’re in an event stream at via an in memory hash.
-
#last_processed_event_id(processor_name) ⇒ Int
Find the last processed event id for a given processor name.
-
#processed_event(processor_name, event_id) ⇒ Object
Update the given processor name to the given event id number.
-
#setup(processor_name) ⇒ Object
(also: #reset_last_processed_event_id)
Register a new processor to track or reset an existing tracker’s last processed event id.
-
#tracked_processors ⇒ Array
Returns an array of all the processors that are being tracked.
Constructor Details
#initialize ⇒ Tracker
Tracking where you’re in an event stream at via an in memory hash. Note: This is not persisted and is generally used for testing.
8 9 10 |
# File 'lib/event_sourcery/memory/tracker.rb', line 8 def initialize @state = Hash.new(0) end |
Instance Method Details
#last_processed_event_id(processor_name) ⇒ Int
Find the last processed event id for a given processor name.
34 35 36 |
# File 'lib/event_sourcery/memory/tracker.rb', line 34 def last_processed_event_id(processor_name) @state[processor_name.to_s] end |
#processed_event(processor_name, event_id) ⇒ Object
Update the given processor name to the given event id number.
25 26 27 |
# File 'lib/event_sourcery/memory/tracker.rb', line 25 def processed_event(processor_name, event_id) @state[processor_name.to_s] = event_id end |
#setup(processor_name) ⇒ Object Also known as: reset_last_processed_event_id
Register a new processor to track or reset an existing tracker’s last processed event id. Will start from 0.
17 18 19 |
# File 'lib/event_sourcery/memory/tracker.rb', line 17 def setup(processor_name) @state[processor_name.to_s] = 0 end |
#tracked_processors ⇒ Array
Returns an array of all the processors that are being tracked.
41 42 43 |
# File 'lib/event_sourcery/memory/tracker.rb', line 41 def tracked_processors @state.keys end |