Django-celery:将请求对象传递给工作者 [英] Django-celery : Passing request Object to worker

查看:343
本文介绍了Django-celery:将请求对象传递给工作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Django请求对象传递给芹菜工作者。尝试传递请求对象时,它将引发错误

How can i pass django request object to celery worker. When try to pass the request object it throws a Error

Can't Pickle Input Objects

似乎芹菜序列化了传递给worker的所有参数。
我尝试使用其他序列化方法(例如JSON)。

It seems that celery serialize any arguments passed to worker. I tried using other serialization methods like JSON.

CELERY_TASK_SERIALIZER = "JSON"

但是它不起作用。

是否可以配置celery以便不会序列化数据。或者我可以在将请求对象传递给工作程序之前将请求对象转换为字符串,然后再次转换回工作程序中的对象。

Is it possible to configure celery so that it won't serialize data. Or can i convert request object to a string before passing to worker and then convert again back to object in worker.

在此先感谢...

推荐答案

您不能腌制Django的请求对象(请参见此问题以获取更多详细信息)。相反,您应该将请求对象中的相关信息传递给Celery任务。

You can't pickle Django's request objects (see this question for more details). Instead you should pass the relevant information from the request object that you need to the Celery tasks.

您应该没有问题,因为大多数对象都可以将其他信息传递给Celery任务没问题就被腌制。

You should have no problem passing other information to a Celery task as most objects can be pickled without a problem.

这篇关于Django-celery:将请求对象传递给工作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆