如何在 Celery 中检查任务状态?

编程入门 行业动态 更新时间:2024-10-26 06:31:34
本文介绍了如何在 Celery 中检查任务状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何检查一个任务是否在 celery 中运行(具体来说,我使用的是 celery-django)?

How does one check whether a task is running in celery (specifically, I'm using celery-django)?

我已经阅读了文档,也用谷歌搜索过,但我看不到这样的电话:

I've read the documentation, and I've googled, but I can't see a call like:

my_example_task.state() == RUNNING

我的用例是我有一个用于转码的外部 (java) 服务.当我发送要转码的文档时,我想检查运行该服务的任务是否正在运行,如果没有,则(重新)启动它.

My use-case is that I have an external (java) service for transcoding. When I send a document to be transcoded, I want to check if the task that runs that service is running, and if not, to (re)start it.

我使用的是当前的稳定版本 - 2.4,我相信.

I'm using the current stable versions - 2.4, I believe.

推荐答案

每个 Task 对象都有一个 .request 属性,其中包含 AsyncRequest> 对象.因此,以下行给出了任务 task 的状态:

Every Task object has a .request property, which contains it AsyncRequest object. Accordingly, the following line gives the state of a Task task:

task.AsyncResult(task.request.id).state

更多推荐

如何在 Celery 中检查任务状态?

本文发布于:2023-11-24 04:13:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623924.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态   如何在   Celery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!