[英]flask celery redis not returning value
試圖學習如何實施芹菜。 我有一個有效的示例,我做了一個redis-cli監視器,我看到它獲取了值並將其返回給瀏覽器,但是當我將該示例更改為自己的東西時,我看到它為我提供了一個密鑰,但是當我嘗試時要查看密鑰的結果,期望將其打印為“ testing123”,它會掛起,redis-cli監視器會顯示無數的“ get”用於芹菜任務。
工作中...
celery = make_celery(app)
@celery.task(name="tasks.add")
def add(x, y):
return x + y
@app.route("/test")
def hello_world(x=16, y=16):
x = int(request.args.get("x", x))
y = int(request.args.get("y", y))
res = add.apply_async((x, y))
context = {"id": res.task_id, "x": x, "y": y}
result = "add((x){}, (y){})".format(context['x'], context['y'])
goto = "{}".format(context['id'])
return jsonify(result=result, goto=goto)
@app.route("/test/result/<task_id>")
def show_result(task_id):
retval = add.AsyncResult(task_id).get(timeout=1.0)
return repr(retval)
不工作...
@celery.task(name="tasks.yieldsomething")
def yieldsomething():
a = 'test123'
return a
@app.route("/yield")
def helloworld2():
res = yieldsomething.apply_async()
return res.task_id
@app.route("/yield/result/<task_id2>")
def show_result2(task_id2):
aretval = yieldsomething.AsyncResult(task_id2).get()
return repr(aretval)
弄清楚我的問題,芹菜不再在后台運行。 重新啟動后,它可以正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.