测试 celery 任务是否仍在处理中
如何测试 celery 中是否仍在处理任务 (task_id)?我有以下场景:
- 在 Django 视图中启动任务
- 将BaseAsyncResult 存储在会话中
- 关闭 celery 守护进程(硬),以便不再处理任务
- 检查任务是否“已死”
有什么想法吗?可以查找 celery 正在处理的所有任务并检查我的任务是否仍然存在吗?
How can I test if a task (task_id) is still processed in celery? I have the following scenario:
- 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为有比在模型中存储任务对象更好的方法。例如,如果您想检查一组任务(并行)是否已完成:
那么在您看来
I think there is a better way than to store a task object in the model. For example, in case you wanted to check if a group of task (parallel) have completed:
Then in your view
在模型中定义一个字段 (PickledObjectField) 来存储 celery 任务:
如果您的任务不特定于任何模型,您应该专门为 celery 任务创建一个字段。
否则我建议使用 django-celery。它有一个很好的监控功能:
http://ask.github.com/celery/userguide/monitoring .html#django-admin-monitor,以良好的图形方式将任务详细信息保存在 django 模型中。
define a field (PickledObjectField) in your model to store the celery task:
In case your task is not specific on any model you should create one specifically for the celery tasks.
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.