Django Celery retry() 任务但继续当前任务
我遇到过这样的情况:我收到第三方服务的响应,表明我的初始请求失败,我应该重试。我正在 Celery 任务中调用该服务。重试调用不会在异常中捕获,并且似乎不是向代理提供新的任务实例并继续当前任务,而是向代理提供任务并退出任务。有没有办法设置重试并继续当前任务?
I have a situation where I receive a response from a third party service indicating that my initial request failed and that I should retry. I'm calling the service in a Celery task. The retry call isn't captured in an exception and it seems that instead of giving a new instance of the task to the broker and continuing with the current task it gives the task to the broker and exits the task. Is there any way to set a retry and continue with the current task?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
task.retry
引发RetryTaskError
异常,该异常用于检测任务是否已重试。请参阅此处的注释: http: //docs.celeryproject.org/en/latest/userguide/tasks.html#retrying-a-task-if-something-fails您可以使用
throw=False
跳过此行为:如果你不要引发异常,当前任务不会被标记为处于 RETRY 状态,
但处于成功/失败状态取决于任务的其余部分是否成功。
由于重试任务将与当前任务共享相同的 uuid,因此如果新任务在当前任务之前返回,则当前任务可能会覆盖新任务的结果。
当然,如果您无论如何忽略任务的结果,这并不重要。
这有道理吗?
task.retry
raises theRetryTaskError
exception, which is used to detect that the task was retried. See the note here: http://docs.celeryproject.org/en/latest/userguide/tasks.html#retrying-a-task-if-something-failsYou can skip this behavior by using
throw=False
:if you don't raise the exception the current task will not be marked as in the RETRY state,
but in the SUCCESS/FAILURE states depending on if the rest of the task succeeds or not.
Since the retry task will share the same uuid as the current task, the current task could override the result of the new task if the new task returns before the current task.
This of course, does not matter if you ignore the results of the task anyway.
Does that make sense?
我的代码略有不同。在本例中,我有一个 celery 任务,它循环遍历接收者列表来发送消息。如果任何发送调用失败,我不希望 celery 任务退出,而是继续其他接收器。
在我的例子中,task.retry(throw=False) 不会发生这种情况。我确实看到任务在那时退出,没有做任何废话。
My code is slightly different. In this case, I have a celery task that loops through a list of receivers to send a message. If any of the send calls fail, I dont want the celery task to exit, but instead continue with the other receivers.
This does not happen with task.retry(throw=False) in my case. I do see the task exiting at that point without doing blah.