[英]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.