Commit 1041da35 authored by Sebastien Robin's avatar Sebastien Robin

generate less conflict error while posting new results to active_process, like...

generate less conflict error while posting new results to active_process, like this it is possible to do computation with many nodes and store results inside only one active process

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17650 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 43007d36
...@@ -35,6 +35,7 @@ from Products.ERP5Type import PropertySheet ...@@ -35,6 +35,7 @@ from Products.ERP5Type import PropertySheet
from BTrees.IOBTree import IOBTree from BTrees.IOBTree import IOBTree
from BTrees.Length import Length from BTrees.Length import Length
from Products.CMFActivity.ActiveObject import DISTRIBUTABLE_STATE, INVOKE_ERROR_STATE, VALIDATE_ERROR_STATE from Products.CMFActivity.ActiveObject import DISTRIBUTABLE_STATE, INVOKE_ERROR_STATE, VALIDATE_ERROR_STATE
from random import randint
from zLOG import LOG from zLOG import LOG
...@@ -82,12 +83,25 @@ class ActiveProcess(Base): ...@@ -82,12 +83,25 @@ class ActiveProcess(Base):
# Declarative constructors # Declarative constructors
constructors = (manage_addActiveProcessForm, addActiveProcess) constructors = (manage_addActiveProcessForm, addActiveProcess)
def _generateRandomId(self):
"""
Generate a random int depending on the size of the result list
"""
random_id = randint(1, 10000 * (self.result_len.value + 1))
return random_id
security.declareProtected(CMFCorePermissions.ManagePortal, 'postResult') security.declareProtected(CMFCorePermissions.ManagePortal, 'postResult')
def postResult(self, result): def postResult(self, result):
if getattr(self, 'result_list', None) is None: if getattr(self, 'result_list', None) is None:
self.result_list = IOBTree() self.result_list = IOBTree()
self.result_len = Length() self.result_len = Length()
self.result_list[self.result_len.value] = result random_id = self._generateRandomId()
_marker = []
# use a random id in order to store result in a way with
# fewer conflict errors
while self.result_list.get(random_id, _marker) is not _marker:
random_id = self._generateRandomId()
self.result_list[random_id] = result
self.result_len.change(1) self.result_len.change(1)
security.declareProtected(CMFCorePermissions.ManagePortal, 'getResultList') security.declareProtected(CMFCorePermissions.ManagePortal, 'getResultList')
......
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