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 |
# 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' Log.debug "adding '#{record}' to database" if CFG.debug? Ping.new(record).save end |
#id_range(first, last) ⇒ Object
38 39 40 |
# File 'lib/ring/sqa/database.rb', line 38 def id_range first, last Ping.distinct.where(:id=>first..last) end |
#nodes_down(first_id) ⇒ Object
25 26 27 28 |
# File 'lib/ring/sqa/database.rb', line 25 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
34 35 36 |
# File 'lib/ring/sqa/database.rb', line 34 def purge older_than=3600 Ping.where{time < (Time.now.utc-older_than).to_i}.delete end |
#up_since?(id, peer) ⇒ Boolean
30 31 32 |
# File 'lib/ring/sqa/database.rb', line 30 def up_since? id, peer Ping.where{id > id}.where(:peer=>peer).count > 0 end |
#update(record_id, result, latency = nil) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/ring/sqa/database.rb', line 16 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 |