[PATCH conductor 5/6] Update uptime methods

jprovazn at redhat.com jprovazn at redhat.com
Tue Jun 5 13:43:42 UTC 2012


From: Jan Provaznik <jprovazn at redhat.com>

Now there can be multiple same events (first/some running event)
which are used when computing uptime. Last saved event is now used.
---
 src/app/models/deployment.rb |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index c3a4a48..8094fd7 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -399,7 +399,7 @@ class Deployment < ActiveRecord::Base
   def uptime_1st_instance
     return nil if events.empty?
 
-    first_running = events.find_by_status_code(:first_running)
+    first_running = events.find_last_by_status_code(:first_running)
     if instances.deployed.empty?
       all_stopped = events.find_last_by_status_code(:all_stopped)
       if all_stopped && first_running && all_stopped.event_time > first_running.event_time
@@ -436,7 +436,7 @@ class Deployment < ActiveRecord::Base
 
   # A deployment "starts" when _all_ instances begin to run
   def start_time
-    if instances.deployed.count == instances.count && ev = events.find_by_status_code(:all_running)
+    if instances.deployed.count == instances.count && ev = events.find_last_by_status_code(:all_running)
       ev.event_time
     else
       nil
@@ -445,8 +445,8 @@ class Deployment < ActiveRecord::Base
 
   # A deployment "ends" when one or more instances stop, assuming they were ever all-running
   def end_time
-    if events.find_by_status_code(:all_running)
-      ev = events.find_by_status_code(:some_stopped) || events.find_by_status_code(:all_stopped)
+    if events.find_last_by_status_code(:all_running)
+      ev = events.find_last_by_status_code(:some_stopped) || events.find_last_by_status_code(:all_stopped)
       ev.present? ? ev.event_time : nil
     else
       nil
-- 
1.7.7.6




More information about the aeolus-devel mailing list