Class: EventSourcery::Memory::Tracker

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeTracker

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.

Returns:

  • (Int)

    the last event id that the given processor has processed



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.

Parameters:

  • processor_name (String)

    the name of the processor to update

  • event_id (Int)

    the number of the event to update



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.

Parameters:

  • processor_name (String)

    the name of the processor to track



17
18
19
# File 'lib/event_sourcery/memory/tracker.rb', line 17

def setup(processor_name)
  @state[processor_name.to_s] = 0
end

#tracked_processorsArray

Returns an array of all the processors that are being tracked.

Returns:

  • (Array)

    an array of names of the tracked processors



41
42
43
# File 'lib/event_sourcery/memory/tracker.rb', line 41

def tracked_processors
  @state.keys
end