Class: MovidaEvents::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/movida_events/stats.rb

Overview

Tracks polling stats

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(last = nil) ⇒ Stats

Create a new MovidaEvents::Stats object

Parameters:

  • last (Integer, nil) (defaults to: nil)

    The last-processed event ID.


31
32
33
34
35
36
# File 'lib/movida_events/stats.rb', line 31

def initialize(last = nil)
  @last = last
  @requests = 0
  @events = 0
  @request_events = 0
end

Instance Attribute Details

#eventsInteger (readonly)

The number of events processed

Returns:

  • (Integer)

    The event count


21
22
23
# File 'lib/movida_events/stats.rb', line 21

def events
  @events
end

#lastInteger? (readonly)

The last-processed event ID

nil if no events have been processed

Returns:

  • (Integer, nil)

    The event ID


11
12
13
# File 'lib/movida_events/stats.rb', line 11

def last
  @last
end

#request_eventsInteger (readonly)

The number of events processed in the current request

Returns:

  • (Integer)

    The request event count


26
27
28
# File 'lib/movida_events/stats.rb', line 26

def request_events
  @request_events
end

#requestsInteger (readonly)

The number of requests made to the API

Returns:

  • (Integer)

    The request count


16
17
18
# File 'lib/movida_events/stats.rb', line 16

def requests
  @requests
end

Instance Method Details

#receive_event(event) ⇒ Object

Update stats when an event is received

Parameters:

  • event (Almodovar::Resource)

    The event received


41
42
43
44
45
# File 'lib/movida_events/stats.rb', line 41

def receive_event(event)
  @last = event.id
  @events += 1
  @request_events += 1
end

#start_requestObject

Update stats when a new request is started


48
49
50
51
# File 'lib/movida_events/stats.rb', line 48

def start_request
  @requests += 1
  @request_events = 0
end