[Erp5-report] r22456 - /erp5/trunk/products/ERP5/Document/Alarm.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Jul 11 17:14:57 CEST 2008


Author: vincent
Date: Fri Jul 11 17:14:53 2008
New Revision: 22456

URL: http://svn.erp5.org?rev=22456&view=rev
Log:
Avoid scanning the whole list of active processes related to an alarm when we just want the most recent one.
When alarm is currently runing, skip latest active result to display the previous one: this way, we display the result of a complete run. This is more consistent for alarms checking big quantities of documents in multiple activities and only displaying an error when one is actualy encountered (an error at the end of a processing batch would be hidden when the next batch starts processing).

Modified:
    erp5/trunk/products/ERP5/Document/Alarm.py

Modified: erp5/trunk/products/ERP5/Document/Alarm.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Alarm.py?rev=22456&r1=22455&r2=22456&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Alarm.py (original)
+++ erp5/trunk/products/ERP5/Document/Alarm.py Fri Jul 11 17:14:53 2008
@@ -331,6 +331,7 @@
 
     The process parameter can be used to retrive sense values for 
     past processes.
+    If it is None, it will return the status of last completed active result.
     """
     method_id = self.getSenseMethodId()
     if process is None:
@@ -479,16 +480,16 @@
     This returns the last active process finished. So it will
     not returns the current one
     """
-    active_process_list = self.getCausalityRelatedValueList(
-                                  portal_type='Active Process')
-
-    def sort_date(a, b):
-      return cmp(a.getStartDate(), b.getStartDate())
-
-    active_process_list.sort(sort_date)
-    if len(active_process_list) > 0:
-      return active_process_list[-1]
-    return None
+    limit = self.isActive() and 2 or 1
+    active_process_list = self.getPortalObject().portal_catalog(
+      portal_type='Active Process', limit=limit,
+      sort_on=(('creation_date', 'DESC'), ),
+      causality_uid=self.getUid())
+    if len(active_process_list) < limit:
+      process = None
+    else:
+      process = active_process_list[-1].getObject()
+    return process
 
   security.declareProtected(Permissions.ModifyPortalContent, 
                             'newActiveProcess')




More information about the Erp5-report mailing list