report idle state in status file, remove obsolete date processing code
smbaker [Wed, 19 Dec 2012 00:14:09 +0000 (16:14 -0800)]
apps/gacks/gackscollector.py

index 5b6d691..b7895ed 100644 (file)
@@ -106,6 +106,9 @@ class ChargeFileManager:
             raise
         return charges
 
+    def get_chargefile_date(self, filename):
+        return int(os.path.basename(filename))
+
     def get_processed_files(self, host):
         """
         Returns a list of files that have already been processed. 
@@ -234,17 +237,19 @@ class ChargeProcessor(threading.Thread):
                     except:
                         self.log.writeTS(traceback.format_exc())
 
-            if len(charges) > 0:
-                latestDate = max([charge["date"] for charge in charges])
+            # Update the summary file, it's used by the UI to show node status.
 
-                sumCharge = sum([charge.get("amount",0.0) for charge in charges if charge["date"]==latestDate])
-                sumResvCharge = sum([charge.get("resv_charge",0.0) for charge in charges if charge["date"]==latestDate])
-                sumCoreCharge = sum([charge.get("core_charge",0.0) for charge in charges if charge["date"]==latestDate])
+            # note: removed latestDate computation here, because a charge file
+            # only has one date for all charges.
 
-                try:
-                    self.node_status.update(host, latestDate, sumCharge, sumResvCharge, sumCoreCharge)
-                except:
-                    self.log.writeTS("ChargeProcessor: error when updating node status table: %s" % traceback.format_exc())
+            sumCharge = sum([charge.get("amount",0.0) for charge in charges])
+            sumResvCharge = sum([charge.get("resv_charge",0.0) for charge in charges])
+            sumCoreCharge = sum([charge.get("core_charge",0.0) for charge in charges])
+
+            try:
+                self.node_status.update(host, self.charge_file_manager.get_chargefile_date(charge_file), sumCharge, sumResvCharge, sumCoreCharge)
+            except:
+                self.log.writeTS("ChargeProcessor: error when updating node status table: %s" % traceback.format_exc())
 
             self.log.writeTS("ChargeProcessor: processed %s of %s charges from file: %s" % (processed_charges, num_charges, charge_file))