简体   繁体   English

Django-celery:将请求对象传递给worker

[英]Django-celery : Passing request Object to worker

How can i pass django request object to celery worker. 我怎样才能将django请求对象传递给芹菜工人。 When try to pass the request object it throws a Error 当尝试传递请求对象时,它会抛出一个错误

Can't Pickle Input Objects

It seems that celery serialize any arguments passed to worker. 似乎celery序列化传递给worker的任何参数。 I tried using other serialization methods like JSON. 我尝试使用其他序列化方法,如JSON。

CELERY_TASK_SERIALIZER = "JSON"

But it is not working. 但它没有用。

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. 或者我可以在传递给worker之前将请求对象转换为字符串,然后再转换回worker中的对象。

Thanks in advance... 提前致谢...

You can't pickle Django's request objects (see this question for more details). 你不能挑选Django的请求对象(有关更多详细信息,请参阅此问题 )。 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. 将其他信息传递给Celery任务应该没有问题,因为大多数对象可以没有问题地被腌制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM