Class: Arkaan::Monitoring::Vigilante

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/arkaan/monitoring/vigilante.rb

Overview

A vigilante is a specific type of service that watches over the infrastructure and give a clear look at its global state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#max_resultsInteger



16
# File 'lib/arkaan/monitoring/vigilante.rb', line 16

field :max_results, type: Integer, default: 20

#reportsArray<Arkaan::monitoring::Results::Report>



20
# File 'lib/arkaan/monitoring/vigilante.rb', line 20

has_many :reports, class_name: 'Arkaan::Monitoring::Results::Report', inverse_of: :vigilante

#tokenString



12
# File 'lib/arkaan/monitoring/vigilante.rb', line 12

field :token, type: String

Instance Method Details

#add_report(report) ⇒ Object

Adds a report to the collection of reports by eventually deleting the oldest one.



30
31
32
33
# File 'lib/arkaan/monitoring/vigilante.rb', line 30

def add_report(report)
  erase_oldest_result if result_full?
  reports << report
end

#erase_oldest_resultObject

Erases the oldest results to keep only MAX - 1 results in the list.



42
43
44
45
# File 'lib/arkaan/monitoring/vigilante.rb', line 42

def erase_oldest_result
  limit = reports.count + 1 - vigilante.max_results
  reports.sort_by(created_at: :asc).limit(limit).each(&:delete)
end

#results_full?Boolean

Checks if the list of reports is already full, or if more can be added.



37
38
39
# File 'lib/arkaan/monitoring/vigilante.rb', line 37

def results_full?
  reports.to_a.count >= max_results
end