Commit 30293bb7 authored by Julien Muchembled's avatar Julien Muchembled

Some review of causality workflow

- delaying 'updateCausalityState' instead of 'calculate'
- make sure 'updateCausalityState' depends on all related simulation movements
- do not process 'updateCausalityState' as long as there remains
  'Delivery_calculate' activities

This fixes r39050 ("fix an error that calculate may be called too early before
a new simulation movement is indexed.").

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42258 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 04092164
......@@ -50,18 +50,9 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string># Note that delivery may have no causality state.\n
# For instance, Accounting Transaction Lines\n
# can be contained in a Accounting Rule Cell\n
# of a Invoice Transaction Rule, and none of\n
# these provide a causality workflow, but\n
# Accounting Transaction Line is also a\n
# possible child of a Accounting Transaction\n
# in the Accounting Transaction Module\n
\n
portal = context.getPortalObject()\n
<value> <string>portal = context.getPortalObject()\n
if portal.portal_workflow.isTransitionPossible(context, \'calculate\'):\n
context.calculate()\n
context.calculate(**kw)\n
else:\n
# Make sure no other node is moving the delivery\n
# to \'diverged\' or \'solved\' state.\n
......@@ -70,7 +61,7 @@ else:\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -52,7 +52,6 @@
<key> <string>_body</string> </key>
<value> <string>delivery = context\n
delivery_path = delivery.getPath()\n
path_and_method_id = (delivery_path, (\'immediateReindexObject\',\'recursiveImmediateReindexObject\'))\n
expand_tag = delivery_path + \'_expand\'\n
tag = delivery_path + \'_updateAppliedRule\'\n
\n
......@@ -71,11 +70,10 @@ activate_kw = { \n
# Serialization is required for avoiding parallel executions of updateAppliedRule\n
# which may generate multiple Root Applied Rules.\n
delivery.activate(\n
after_path_and_method_id=path_and_method_id,\n
after_tag=expand_tag,\n
tag=tag,\n
priority=priority,\n
serialization_tag=delivery_path,\n
serialization_tag=tag,\n
).Delivery_updateAppliedRule(activate_kw=activate_kw)\n
</string> </value>
</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>delivery_movement = context.getDeliveryValue()\n
\n
if delivery_movement is not None:\n
delivery = delivery_movement.getRootDeliveryValue()\n
delivery.activate().Delivery_calculate()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SimulationMovement_calculateCausalityState</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -52,7 +52,8 @@
<key> <string>_body</string> </key>
<value> <string>delivery = state_change[\'object\']\n
activate_kw = state_change[\'kwargs\'].get(\'activate_kw\') or {}\n
delivery.activate(**activate_kw).updateCausalityState()\n
tag = delivery.getPath() + \'_calculate\'\n
delivery.activate(after_tag=tag, **activate_kw).updateCausalityState()\n
</string> </value>
</item>
<item>
......
......@@ -68,7 +68,9 @@ if len(delivery_solve_property_dict) or len(divergence_to_accept_list) \\\n
delivery_builder.solveDivergence(delivery_relative_url,\n
divergence_to_accept_list=divergence_to_accept_list,\n
divergence_to_adopt_list=divergence_to_adopt_list)\n
delivery.activate().updateCausalityState()\n
# There could be a pending \'Delivery_calculate\' activity if we solved from\n
# \'calculating\' state, so wait that it is gone before updating causality state.\n
delivery.activate(after_tag=delivery.getPath() + \'_calculate\').updateCausalityState()\n
</string> </value>
</item>
<item>
......
......@@ -27,15 +27,15 @@
<item>
<key> <string>after_script_name</string> </key>
<value>
<list>
<string>SimulationMovement_calculateCausalityState</string>
</list>
<tuple/>
</value>
</item>
<item>
<key> <string>before_commit_script_name</string> </key>
<value>
<tuple/>
<list>
<string>SimulationMovement_calculateCausalityState</string>
</list>
</value>
</item>
<item>
......
......@@ -50,15 +50,7 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>simulation_movement = state_change[\'object\']\n
\n
# It is not quite useful to invoke the method calculate when a newly created\n
# simulation movement is not indexed yet, so it is better to wait for the indexing\n
# to be done.\n
path = simulation_movement.getPath()\n
method_id_list = (\'immediateReindexObject\', \'recursiveImmediateReindexObject\')\n
simulation_movement.activate(after_path_and_method_id=(path, method_id_list)) \\\n
.SimulationMovement_calculateCausalityState()\n
<value> <string>state_change[\'object\'].calculate()\n
</string> </value>
</item>
<item>
......
934
\ No newline at end of file
935
\ No newline at end of file
......@@ -27,6 +27,7 @@
#
##############################################################################
import transaction
import zope.interface
from AccessControl import ClassSecurityInfo
from Products.CMFCore.utils import getToolByName
......@@ -241,6 +242,35 @@ class SimulationMovement(PropertyRecordableMixin, Movement, ExplainableMixin):
#######################################################
# Causality Workflow Methods
security.declareProtected(Permissions.ModifyPortalContent, 'calculate')
def calculate(self):
"""Move related delivery in 'calculating' state by activity
Activity to update causality state is delayed until all related simulation
movement are reindexed.
This method should be only called by
simulation_movement_causality_interaction_workflow.
"""
delivery = self.getDeliveryValue()
if delivery is not None:
delivery = delivery.getRootDeliveryValue()
tv = getTransactionalVariable()
path = self.getPath()
delivery_path = delivery.getPath()
key = 'SimulationMovement.calculate', delivery_path
try:
tv[key].append(path)
except KeyError:
tv[key] = [path]
def before_commit():
method_id_list = ('immediateReindexObject',
'recursiveImmediateReindexObject')
tag = delivery_path + '_calculate'
delivery.activate(tag=tag).Delivery_calculate(activate_kw=
{'after_path_and_method_id': (tv[key], method_id_list)})
tv[key] = None # disallow further calls to 'calculate'
transaction.get().addBeforeCommitHook(before_commit)
security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, force=0, **kw):
"""
......
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