在执行 Products.CMFCore.interfaces.IActionSucceededEvent 时进行加薪是否会中止工作流程的 ZODB 事务?

发布于 2024-12-03 02:23:32 字数 1071 浏览 0 评论 0原文

假设我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤独难免 2024-12-10 02:23:32
  1. 是的,如果您在其中一个处理程序中提出任何异常
    整个交易将失败并且将被还原
  2. 不,使用多个订阅者不会有问题
    相同的接口。它们将按照注册顺序执行。
  3. 不,使用 IActionWillBeInvokedEvent 没有帮助。它在 wf 转换之前触发,但如果引发异常,事务无论如何都会失败。
  1. Yes, if you raise any exception in one of your handlers the
    entire transaction will fail and it will be reverted
  2. no, you wouldn't have problems using more than one subscriber for
    the same interfaces. They would be execute in order of registration.
  3. no, using IActionWillBeInvokedEvent will not help. It's fired before wf transition, but if you raise exceptions the transaction will fail anyway.
痴情换悲伤 2024-12-10 02:23:32

您可以通过将 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).

缪败 2024-12-10 02:23:32

根据 @Giacomo 的回复,如果任何未捕获的异常,交易将被中止。因此,最好的选择是找出您想要容忍的错误并在订阅者中捕获这些异常,记录异常,然后继续,以便事务仍将被提交:

import logging
logger = logging.getLogger('mynamespace.myproduct')
...
def actionSucceeded(obj, event):
    ...
    try:
        my_dangerous_stuff(...)
    except (TolerableException, AnotherTolerableException, ...):
        logger.exception('Encountered an error while handling foo event')
    ...

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:

import logging
logger = logging.getLogger('mynamespace.myproduct')
...
def actionSucceeded(obj, event):
    ...
    try:
        my_dangerous_stuff(...)
    except (TolerableException, AnotherTolerableException, ...):
        logger.exception('Encountered an error while handling foo event')
    ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文