Commit 7237600b authored by Vincent Pelletier's avatar Vincent Pelletier

New worklist cache behaviour to avoid problems when alarm and users were...

New worklist cache behaviour to avoid problems when alarm and users were triggering a refresh in parallel:
- only the alarm can trigger a worklist refresh
- refreshing uses DELETE/INSERT instead of DROP/CREATE/INSERT.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25038 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ac947f59
...@@ -53,27 +53,15 @@ ...@@ -53,27 +53,15 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>from ZODB.POSException import ConflictError\n <value> <string># Wrapper for Base_zGetCountFromWorklistTable\n
# Wrapper for Base_zGetCountFromWorklistTable\n \n
where_expression = query.asSQLExpression()[\'where_expression\']\n where_expression = query.asSQLExpression()[\'where_expression\']\n
try:\n \n
result = context.Base_zGetCountFromWorklistTable(\n return context.Base_zGetCountFromWorklistTable(\n
where_expression=where_expression,\n where_expression=where_expression,\n
select_expression=select_expression,\n select_expression=select_expression,\n
group_by_expression=group_by_expression,\n group_by_expression=group_by_expression,\n
**kw)\n **kw)\n
except ConflictError:\n
raise\n
except:\n
# Possibly a SQL error caused by a non-existing table.\n
# Attemp a refresh and retry without error handling.\n
context.Base_refreshWorklistTableContent()\n
result = context.Base_zGetCountFromWorklistTable(\n
where_expression=where_expression,\n
select_expression=select_expression,\n
group_by_expression=group_by_expression,\n
**kw)\n
return result\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -114,14 +102,11 @@ return result\n ...@@ -114,14 +102,11 @@ return result\n
<string>select_expression</string> <string>select_expression</string>
<string>group_by_expression</string> <string>group_by_expression</string>
<string>kw</string> <string>kw</string>
<string>ZODB.POSException</string>
<string>ConflictError</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>where_expression</string> <string>where_expression</string>
<string>_apply_</string> <string>_apply_</string>
<string>context</string> <string>context</string>
<string>result</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="SQL" module="Products.ZSQLMethods.SQL"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_arg</string> </key>
<value>
<object>
<klass>
<global name="Args" module="Shared.DC.ZRDB.Aqueduct"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_data</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>_keys</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>connection_id</string> </key>
<value> <string>erp5_sql_connection</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_zClearWorklistTable</string> </value>
</item>
<item>
<key> <string>src</string> </key>
<value> <string>DELETE FROM worklist_cache</string> </value>
</item>
<item>
<key> <string>template</string> </key>
<value>
<object>
<klass>
<global name="__newobj__" module="copy_reg"/>
</klass>
<tuple>
<global name="SQL" module="Shared.DC.ZRDB.DA"/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string encoding="cdata"><![CDATA[
<string>
]]></string> </value>
</item>
<item>
<key> <string>_vars</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>globals</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>raw</string> </key>
<value> <string>DELETE FROM worklist_cache</string> </value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
22 24
\ No newline at end of file \ No newline at end of file
...@@ -34,6 +34,7 @@ from Acquisition import aq_base ...@@ -34,6 +34,7 @@ from Acquisition import aq_base
from Persistence import Persistent from Persistence import Persistent
from Globals import PersistentMapping from Globals import PersistentMapping
from itertools import izip from itertools import izip
from MySQLdb import ProgrammingError
def DCWorkflowDefinition_notifyWorkflowMethod(self, ob, transition_list, args=None, kw=None): def DCWorkflowDefinition_notifyWorkflowMethod(self, ob, transition_list, args=None, kw=None):
''' '''
...@@ -557,6 +558,14 @@ def WorkflowTool_listActions(self, info=None, object=None, src__=False): ...@@ -557,6 +558,14 @@ def WorkflowTool_listActions(self, info=None, object=None, src__=False):
WorkflowTool.listActions = WorkflowTool_listActions WorkflowTool.listActions = WorkflowTool_listActions
def WorkflowTool_refreshWorklistCache(self): def WorkflowTool_refreshWorklistCache(self):
"""
Refresh worklist cache table.
- delete everything from that table
- if it fails, create the table
- insert new lines
- if it fails, recrete the table and retry
"""
# Contrary to WorkflowTool_listActions, related keys are NOT supported. # Contrary to WorkflowTool_listActions, related keys are NOT supported.
Base_zInsertIntoWorklistTable = getattr(self, 'Base_zInsertIntoWorklistTable', None) Base_zInsertIntoWorklistTable = getattr(self, 'Base_zInsertIntoWorklistTable', None)
if Base_zInsertIntoWorklistTable is not None: if Base_zInsertIntoWorklistTable is not None:
...@@ -572,7 +581,14 @@ def WorkflowTool_refreshWorklistCache(self): ...@@ -572,7 +581,14 @@ def WorkflowTool_refreshWorklistCache(self):
worklist_dict[wf_id] = a worklist_dict[wf_id] = a
# End of duplicated code # End of duplicated code
if len(worklist_dict): if len(worklist_dict):
self.Base_zCreateWorklistTable() # Create (or flush existing) table try:
self.Base_zClearWorklistTable()
except ProgrammingError, error_value:
import pdb; pdb.set_trace()
# 1146 = table does not exist
if error_value[0] != 1146:
raise
self.Base_zCreateWorklistTable()
portal_catalog = getToolByName(self, 'portal_catalog') portal_catalog = getToolByName(self, 'portal_catalog')
search_result = portal_catalog.unrestrictedSearchResults search_result = portal_catalog.unrestrictedSearchResults
acceptable_key_dict = portal_catalog.getSQLCatalog().getColumnMap() acceptable_key_dict = portal_catalog.getSQLCatalog().getColumnMap()
...@@ -613,7 +629,14 @@ def WorkflowTool_refreshWorklistCache(self): ...@@ -613,7 +629,14 @@ def WorkflowTool_refreshWorklistCache(self):
if column_id in value_column_dict: if column_id in value_column_dict:
value_column_dict[column_id].append(value) value_column_dict[column_id].append(value)
if len(value_column_dict[COUNT_COLUMN_TITLE]): if len(value_column_dict[COUNT_COLUMN_TITLE]):
Base_zInsertIntoWorklistTable(**value_column_dict) try:
Base_zInsertIntoWorklistTable(**value_column_dict)
except ProgrammingError:
LOG('WorkflowTool', 100, 'Insertion in worklist cache table ' \
'failed. Recreating table and retrying.',
error=sys.exc_info())
self.Base_zCreateWorklistTable()
Base_zInsertIntoWorklistTable(**value_column_dict)
WorkflowTool.refreshWorklistCache = WorkflowTool_refreshWorklistCache WorkflowTool.refreshWorklistCache = WorkflowTool_refreshWorklistCache
......
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