测试芹菜任务是否仍在处理中 [英] Test if a celery task is still being processed
问题描述
如何在芹菜中测试任务(task_id)是否仍然处理?我有以下情况:
How can I test if a task (task_id) is still processed in celery? I have the following scenario:
- 在Django视图中启动任务
- 将BaseAsyncResult存储在会话
- 关闭芹菜守护进程(硬),以便任务不再被处理
- 检查任务是否为死
- Start a task in a Django view
- Store the BaseAsyncResult in the session
- Shutdown the celery daemon (hard) so the task is not processed anymore
- Check if the task is 'dead'
任何想法?可以查询芹菜处理的所有任务,并检查我的是否仍然存在?
Any ideas? Can a lookup all task being processed by celery and check if mine is still there?
推荐答案
在您的...中定义一个字段(PickledObjectField)存储芹菜任务的模型:
define a field (PickledObjectField) in your model to store the celery task:
class YourModel(models.Model):
.
.
celery_task = PickledObjectField()
.
.
def task():
self.celery_task = SubmitTask.apply_async(args = self.task_detail())
self.save()
如果您的任务不是特定于任何型号,您应该专门为芹菜任务创建一个。
In case your task is not specific on any model you should create one specifically for the celery tasks.
或者我建议使用django-celery。它有一个很好的监控功能:
http ://ask.github.com/celery/userguide/monitoring.html#django-admin-monitor ,将任务详细信息以漂亮的图形方式保存在django模型中。
or else I suggest using django-celery. It has a nice monitoring feature:
http://ask.github.com/celery/userguide/monitoring.html#django-admin-monitor, saves the tasks details in a django model in a nice graphical way.
这篇关于测试芹菜任务是否仍在处理中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!