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