Class: Ring::SQA::Database
- Inherits:
-
Object
- Object
- Ring::SQA::Database
- Defined in:
- lib/ring/sqa/database.rb,
lib/ring/sqa/database/model.rb
Defined Under Namespace
Classes: Ping
Instance Method Summary collapse
- #add(record) ⇒ Object
- #id_range(first, last) ⇒ Object
- #nodes_down(first_id) ⇒ Object
- #purge(older_than = 3600) ⇒ Object
- #up_since?(id, peer) ⇒ Boolean
- #update(record_id, result, latency = nil) ⇒ Object
Instance Method Details
#add(record) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/ring/sqa/database.rb', line 8 def add record record[:time] = Time.now.utc.to_i record[:latency] = nil record[:result] = 'no response' ping = Ping.new(record).save Log.debug "added '#{record}' to database with id #{ping.id}" if CFG.debug? return ping end |
#id_range(first, last) ⇒ Object
39 40 41 |
# File 'lib/ring/sqa/database.rb', line 39 def id_range first, last Ping.distinct.where(:id=>first..last) end |
#nodes_down(first_id) ⇒ Object
26 27 28 29 |
# File 'lib/ring/sqa/database.rb', line 26 def nodes_down first_id max_id = (Ping.max(:id) or first_id) [max_id, id_range(first_id, max_id).exclude(:result => 'ok')] end |
#purge(older_than = 3600) ⇒ Object
35 36 37 |
# File 'lib/ring/sqa/database.rb', line 35 def purge older_than=3600 Ping.where{time < (Time.now.utc-older_than).to_i}.delete end |
#up_since?(id, peer) ⇒ Boolean
31 32 33 |
# File 'lib/ring/sqa/database.rb', line 31 def up_since? id, peer Ping.where{id > id}.where(:peer=>peer).count > 0 end |
#update(record_id, result, latency = nil) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/ring/sqa/database.rb', line 17 def update record_id, result, latency=nil if record = Ping[record_id] Log.debug "updating record_id '#{record_id}' with result '#{result}' and latency '#{latency}'" if CFG.debug? record.update(:result=>result, :latency=>latency) else Log.error "wanted to update record_id #{record_id}, but it does not exist" end end |