我使用RabbitMQ作为消息代理,使用Celery作为任务队列来处理队列内容。让我们举一个基本的例子,我们想要添加两个数字x和y。
我已将共享任务创建为:
- 任务. py**
from celery import shared_task
@shared_task
def add(x, y):
return x + y
我看到当我将内容推送到队列时,数据存储为
(myprojectenv) root@ubuntu-s-1vcpu-1gb-blr1-02:/etc/myproject# python manage.py shell
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from myproject.tasks import add
>>> add.delay(5, 5)
<AsyncResult: 88f4d5c2-f68a-42c1-acda-d64593df1899>
但是,我希望以不同的格式存储数据,例如
{operation : 'add', listOfNumbers : [5, 5]}
如何改变数据实际推入队列的方式呢?在获取数据时,我可以获取字典,解包值并处理这些值
1条答案
按热度按时间gopyfrb31#