谷歌应用程序引擎任务队列 [英] google app engine taskqueues
问题描述
在Google App Engine中使用任务队列时遇到一些问题.我尝试过与此网站相同的操作: https://developers.google.com/appengine/docs/python/taskqueue /overview-push
Have some problems using taskqueues in google app engine. I tried doing the same as in this site: https://developers.google.com/appengine/docs/python/taskqueue/overview-push
但是似乎我的任务从未执行过,出现此错误:
But it seems like my task is never executed, I get this error:
警告2012-11-25 15:29:21,258 taskqueue_stub.py:1978]任务task1无法执行.该任务将在12.800秒后重试
WARNING 2012-11-25 15:29:21,258 taskqueue_stub.py:1978] Task task1 failed to execute. This task will retry in 12.800 seconds
除以下内容外,代码基本相同:
The code is mainly the same except of these:
class CounterWorker(webapp.RequestHandler):
def init(self): # should run at most 1/s
def txn():
logging.info("bla")
db.run_in_transaction(txn)
我只是添加如下任务:
taskqueue.add(url='/worker')
我真正想要的只是运行一个不超时的代码块.所以我读到我可以使用任务队列.但是我似乎无法使其正常工作.
What I really want is just running a block of code that dont timeouts. So I read I could use taskqueues. But I cant seem to make it work.
推荐答案
如果您只想执行"vanilla"任务,那么请看一下延迟函数.
If you just want to execute tasks "vanilla" then have a look at the deferred functions.
from google.appengine.ext import deferred
def do_something_expensive(a, b, c=None):
logging.info("Doing something expensive!")
# Do your work here
# Somewhere else
deferred.defer(do_something_expensive, "Hello, world!", 42, c=True)
您不需要url/webapp处理程序,因为您可以直接传递该函数.
You won't need a url/webapp handler as you can pass the function directly.
这篇关于谷歌应用程序引擎任务队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!