在执行 Products.CMFCore.interfaces.IActionSucceededEvent 时进行加薪是否会中止工作流程的 ZODB 事务?
假设我有 mynamespace.myproduct:
<subscriber for="..interfaces.myinterface.IMyInterface
Products.CMFCore.interfaces.IActionSucceededEvent"
handler=".handlers.actionSucceeded"
/>
和 mynamespace.myproduct2:
<subscriber for="..interfaces.myinterface.IMyInterface
Products.CMFCore.interfaces.IActionSucceededEvent"
handler=".handlers.actionSucceeded"
/>
(处理程序在每个产品上执行不同的操作,即使它们在此示例中具有相同的名称)
我有具有自定义工作流程的自定义类型。我将使用 doActionFor
从 Python 进行工作流转换,并在触发 IActionSucceededEvent
时执行一系列操作。
我的问题是:如果我在发生错误时对任何 .handlers.actionSucceeded
引发异常,doActionFor
调用是否会恢复(即使在 IActionSucceededEvent
之后)代码> 已运行)?如果没有,如果我使用 IActionWillBeInvokedEvent
,我能够实现我的目标吗?如果我拥有两个不同的产品,并且都使用 Products.CMFCore.interfaces.IActionSucceededEvent
来实现相同的 ..interfaces.myinterface.IMyInterface
接口,是否会有问题?
Suppose I have mynamespace.myproduct:
<subscriber for="..interfaces.myinterface.IMyInterface
Products.CMFCore.interfaces.IActionSucceededEvent"
handler=".handlers.actionSucceeded"
/>
and mynamespace.myproduct2:
<subscriber for="..interfaces.myinterface.IMyInterface
Products.CMFCore.interfaces.IActionSucceededEvent"
handler=".handlers.actionSucceeded"
/>
(the handlers do different stuff, on each product, even if they have the same name on this example)
I have a custom type that has a custom workflow. I'm going to do a workflow transition from Python, using doActionFor
, and do a bunch of things when IActionSucceededEvent
is triggered.
My question is: if I raise an exception on any of .handlers.actionSucceeded
if an error occurs, will the doActionFor
call be reverted (even after IActionSucceededEvent
was run)? If not, if I use IActionWillBeInvokedEvent
, will I be able to accomplish my goals? Will I have a problem for having two different products, both using Products.CMFCore.interfaces.IActionSucceededEvent
for the same ..interfaces.myinterface.IMyInterface
interface?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
整个交易将失败并且将被还原
相同的接口。它们将按照注册顺序执行。
entire transaction will fail and it will be reverted
the same interfaces. They would be execute in order of registration.
您可以通过将 Plone 调试级别设置为 DEBUG(默认为 info)来检查这一点,并将日志输出放入事件处理程序。在 DEBUG 日志记录中,Plone 打印事务边界。
如果您的异常在引发异常时导致“505 内部服务器错误”,它也会展开任何正在进行的事务(除非手动调用 transaction.commit(),但正常代码不应出现这种情况)。
You can check this by turning Plone debug level to DEBUG (default is info) and put logging output to the event handlers. In DEBUG logging Plone prints transaction boundaries.
If your exception causes "505 Internal Server error" when the exception is raised it will also unroll any on-going transaction (unless transaction.commit() is called manually, but that should not be the case for the normal code).
根据 @Giacomo 的回复,如果任何未捕获的异常,交易将被中止。因此,最好的选择是找出您想要容忍的错误并在订阅者中捕获这些异常,记录异常,然后继续,以便事务仍将被提交:
As per @Giacomo's response, the transaction will be aborted for any exception that isn't caught. So your best bet is to find out what errors you want to tolerate and catch those exceptions in your subscriber, log the exception, and then move on so the transaction will still be committed: