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

时间:2013-12-02 08:19:05

标签: python celery

我有一个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:

1 个答案:

答案 0 :(得分:-1)

不是理想的做法,但它应该可以正常工作:

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)