问题描述
如何检查一项任务是否在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.
I我使用的是当前的稳定版本-我相信是2.4。
I'm using the current stable versions - 2.4, I believe.
推荐答案
每个任务
对象具有 .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中检查任务状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!