Class: TacScribe::EventProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/tac_scribe/event_processor.rb

Overview

Processes the events emitted by the Ruby Tacview Client

Constant Summary collapse

@@ignored_units =
Concurrent::Set.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache:, datastore:, event_queue:, whitelist: nil) ⇒ EventProcessor

Returns a new instance of EventProcessor.



15
16
17
18
19
20
21
22
# File 'lib/tac_scribe/event_processor.rb', line 15

def initialize(cache:, datastore:, event_queue:, whitelist: nil)
  @cache = cache
  @datastore = datastore
  @event_queue = event_queue
  @whitelist = whitelist
  self.events_processed = 0
  self.events_ignored = 0
end

Instance Attribute Details

#events_ignoredObject

Returns the value of attribute events_ignored.



13
14
15
# File 'lib/tac_scribe/event_processor.rb', line 13

def events_ignored
  @events_ignored
end

#events_processedObject

Returns the value of attribute events_processed.



13
14
15
# File 'lib/tac_scribe/event_processor.rb', line 13

def events_processed
  @events_processed
end

Instance Method Details

#process_event(wrapped_event) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/tac_scribe/event_processor.rb', line 36

def process_event(wrapped_event)
  case wrapped_event[:type]
  when :update_object
    update_object(wrapped_event[:event], wrapped_event[:time])
  when :delete_object
    delete_object(wrapped_event[:object_id])
  when :set_latitude
    update_latitude wrapped_event[:value]
  when :set_longitude
    update_longitude wrapped_event[:value]
  end
end

#startObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tac_scribe/event_processor.rb', line 24

def start
  loop do
    wrapped_event = @event_queue.shift
    process_event(wrapped_event)
  rescue StandardError => e
    puts wrapped_event
    puts e.inspect
    puts e.backtrace
    next
  end
end