如何在 Celery 中检查任务状态? [英] How to check task status in 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 中检查任务状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!