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

编程入门 行业动态 更新时间:2024-10-26 04:20:49
本文介绍了如何在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.

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中检查任务状态?

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

发布评论

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

>www.elefans.com

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