Commit e681ea49 authored by Vincent Pelletier's avatar Vincent Pelletier

Avoid scanning the whole list of active processes related to an alarm when we...

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).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22456 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b0d76b1c
......@@ -331,6 +331,7 @@ class Alarm(XMLObject, PeriodicityMixin):
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 @@ Alarm URL: %s
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')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment