0
我目前正在嘗試使用Flask框架排列App Engine中的任務,但我遇到了一些困難。我運行我的代碼,並且當我檢查localhost:8000/taskqueue中的管理服務器時,似乎任務正常排隊。但是,控制檯反覆打印以下錯誤:App Engine開發服務器無法執行排隊的任務 - 沒有任何堆棧跟蹤
WARNING 2016-10-05 17:08:09,560 taskqueue_stub.py:1981] Task task1 failed to execute. This task will retry in 0.100 seconds
此外,它似乎並不像所需的代碼正在執行。
我的問題是,爲什麼我的代碼不工作?我對這個非常寬泛的問題表示歉意,但是沒有任何堆棧跟蹤可以指導我更具體地瞭解。我已簡化了我的代碼,以使我的錯誤可重現。下面的代碼應該將短語「sample task」打印到控制檯上5次。但是,這不會發生。
#main.py
from google.appengine.api.taskqueue import taskqueue
from flask import Flask, Response
app = Flask(__name__)
@app.route("/get")
def get():
for i in range(5):
# attempt to execute the desired function 5 times
# the message "sample task" should be printed to the console five times
task = taskqueue.add(
queue_name='my-queue',
url='/sample_task',
)
message += 'Task {} enqueued, ETA {}.<br>'.format(task.name, task.eta)
response = Response(message)
return response
@app.route("/sample_task")
def sample_task():
message = "sample task"
print (message)
return Response(message)
if __name__ == "__main__":
app.run()
的app.yaml
# app.yaml
runtime: python27
api_version: 1
threadsafe: true
# [START handlers]
handlers:
- url: /sample_task
script: main.app
login: admin
- url: /get
script: main.app
login: admin
queue.yaml中
# queue.yaml
queue:
- name: my-queue
rate: 1/s
bucket_size: 40
max_concurrent_requests: 1
@Anthon:感謝您抽出寶貴的時間來解決我的問題。反引號在那裏,因爲我有這樣的印象,他們有必要在StackOverflow中呈現代碼塊。看起來我錯了。感謝您指出。代碼塊現在已被糾正。此外,我已經找到了解決這個問題的方法。它看起來像我只需要在路由器的輸入參數中添加'methods ='POST''。但仍然,感謝您檢查我的代碼。 –