繁体   English   中英

如何将任务添加到芹菜队列?

[英]How to add tasks to celery queue?

我有一个JSON格式的字符串。

[{"from":"9871098", "to": " 123455", "message" : "Hello World"}, {"from":"9871098", "to": " 123455", "message" : "Hello World"}, {"from":"9871098", "to": " 123455", "message" : "Hello World"}, {"from":"9871098", "to": " 123455", "message" : "Hello World"}]

我想每5秒将每个条目添加到队列中,然后相应地处理每个消息。 我该怎么做?

这是我不完整的代码。 我将如何处理?

from celery import Celery
import json
app = Celery('tasks', broker='amqp://guest@localhost//')

@app.task
def data_pusher():
    message_file = json.loads("/Desktop/file.json")
    for data in message_file:

这不是理想的方式,但是应该可以正常工作:

from celery import Celery
import json
from time import sleep
app = Celery('tasks', broker='amqp://guest@localhost//')

@app.task
def data_pusher():
    message_file = json.loads("/Desktop/file.json")
    for data in message_file:
        // add the data line to the queue
        sleep(5)

暂无
暂无

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

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