简单 Google App Engine 任务队列教程?烧瓶/Python/GAE
Simple Google App Engine Task Queue tutorial? Flask/ Python/ GAE
我什至无法让任务队列触发简单的打印语句。
不知道是不是我的app结构不对...
最简单的任务队列示例及其结构是什么?
因为这对我不起作用:
@app.route('/task', methods=["GET", "POST"])
def testtask():
print "Hi, I'm calling the task"
taskqueue.add(
url='/execute_task'
)
return "I called the task"
@app.route('/execute_task', methods=["GET", "POST"])
def execute_task():
print "I'm executing the task"
return "I excecuted the task"
两条路线都在app.yaml文件中:
- url: /execute_task
script: app.app
login: admin
- url: /task
script: app.app
login: admin
在终端中:
Hi, I'm calling the task INFO 2018-01-28 23:00:49,521
module.py:788] default: "GET /task HTTP/1.1" 200 17
http://localhost:8000/taskqueue
显示:
队列名称最大速率桶大小队列中最旧的任务 (UTC) 任务
默认 5.00/s 5 2018/01/28 22:59:59(0:04:44 前)2
向任务显示的 print
语句没有意义。你永远不会看到它。只有任务可以看到它。让任务通过日志与您对话。
看看这是否更有意义:
from flask import Response
from google.appengine.api import taskqueue
import logging
@app.route('/task', methods=["GET", "POST"])
def testtask():
logging.info("sending task to queue in testtask...")
taskqueue.add(
url = "/execute_task",
name = "task_name_here",
method = "POST",
params = {
"sender": "me"
}
)
return Response("sending task to queue... Check logs", mimetype='text/plain', status=200)
@app.route('/execute_task', methods=["GET", "POST"])
def execute_task():
logging.info("I did the task")
logging.info("params: {}".format(request.form))
return Response("did it. You'll never see this message", mimetype='text/plain', status=200)
我什至无法让任务队列触发简单的打印语句。
不知道是不是我的app结构不对...
最简单的任务队列示例及其结构是什么?
因为这对我不起作用:
@app.route('/task', methods=["GET", "POST"])
def testtask():
print "Hi, I'm calling the task"
taskqueue.add(
url='/execute_task'
)
return "I called the task"
@app.route('/execute_task', methods=["GET", "POST"])
def execute_task():
print "I'm executing the task"
return "I excecuted the task"
两条路线都在app.yaml文件中:
- url: /execute_task
script: app.app
login: admin
- url: /task
script: app.app
login: admin
在终端中:
Hi, I'm calling the task INFO 2018-01-28 23:00:49,521 module.py:788] default: "GET /task HTTP/1.1" 200 17
http://localhost:8000/taskqueue
显示:
队列名称最大速率桶大小队列中最旧的任务 (UTC) 任务
默认 5.00/s 5 2018/01/28 22:59:59(0:04:44 前)2
向任务显示的 print
语句没有意义。你永远不会看到它。只有任务可以看到它。让任务通过日志与您对话。
看看这是否更有意义:
from flask import Response
from google.appengine.api import taskqueue
import logging
@app.route('/task', methods=["GET", "POST"])
def testtask():
logging.info("sending task to queue in testtask...")
taskqueue.add(
url = "/execute_task",
name = "task_name_here",
method = "POST",
params = {
"sender": "me"
}
)
return Response("sending task to queue... Check logs", mimetype='text/plain', status=200)
@app.route('/execute_task', methods=["GET", "POST"])
def execute_task():
logging.info("I did the task")
logging.info("params: {}".format(request.form))
return Response("did it. You'll never see this message", mimetype='text/plain', status=200)