Google App Engine:由 cron 调用 Cron 处理程序,但没有运行任何代码
我有以下问题。我在 Google App Engine 中定义了一个 cron 作业,但是我的 get 方法没有被调用(或者准确地说,它每隔一段时间就会被调用一次 - 如果我手动运行它,它第一次不会执行任何操作,但在第二次时)它工作完美)。这是 cron 调用的日志记录的输出:
2011-07-04 11:39:08.500 /suggestions/ 200 489ms 70cpu_ms 0kb AppEngine-Google; (+http://code.google.com/appengine)
0.1.0.1 - - [04/Jul/2011:11:39:08 -0700] "GET /suggestions/ HTTP/1.1" 200 0 - "AppEngine-Google; (+http://code.google.com/appengine)" "bazinga-match.appspot.com" ms=489 cpu_ms=70 api_cpu_ms=0 cpm_usd=0.001975 queue_name=__cron task_name=a449e27ff383de24ff8fc5d5f05f2aae
如您所见,它在 /suggestions/
上发出 GET
请求,但没有任何反应,包括我的日志消息(它们是打印,当我第二次手动运行它时)。您知道为什么会发生这种情况吗?
我的处理程序:
class SuggestionsHandler(RequestHandler):
def get(self):
logging.debug('Creating suggestions')
for key in db.Query(User, keys_only=True).order('last_suggestion'):
make_suggestion(key)
logging.debug('Done creating suggestions')
print
print('Done creating suggestions')
这是我的 cron.yaml:
cron:
- description: daily suggestion creation
url: /suggestions/
schedule: every 6 hours
以及我的 app.yaml 的适当部分:
- url: /suggestions/
script: cron.py
login: admin
I have a following problem. I have defined a cron job in Google App Engine, but my get method is not called (or to be precise it is called every other time - if I run it manually it doesn't do anything at the first time, but at the second it works flawlessly). This is output from logging for the call made by cron:
2011-07-04 11:39:08.500 /suggestions/ 200 489ms 70cpu_ms 0kb AppEngine-Google; (+http://code.google.com/appengine)
0.1.0.1 - - [04/Jul/2011:11:39:08 -0700] "GET /suggestions/ HTTP/1.1" 200 0 - "AppEngine-Google; (+http://code.google.com/appengine)" "bazinga-match.appspot.com" ms=489 cpu_ms=70 api_cpu_ms=0 cpm_usd=0.001975 queue_name=__cron task_name=a449e27ff383de24ff8fc5d5f05f2aae
As you can see it makes GET
request on /suggestions/
, but nothing happens, including my log messages (they are printed, when I run it second time manually). Do you have any idea, why this might be happening?
My handler:
class SuggestionsHandler(RequestHandler):
def get(self):
logging.debug('Creating suggestions')
for key in db.Query(User, keys_only=True).order('last_suggestion'):
make_suggestion(key)
logging.debug('Done creating suggestions')
print
print('Done creating suggestions')
This is my cron.yaml:
cron:
- description: daily suggestion creation
url: /suggestions/
schedule: every 6 hours
and proper section of my app.yaml:
- url: /suggestions/
script: cron.py
login: admin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在处理程序文件底部的
main
之后缺少此声明:第一次运行处理程序脚本时,App Engine 只是导入它,并且此代码段在这种情况下运行您的 main。对于后续请求,App Engine 会运行
main
函数(如果您定义了该函数)。You're missing this declaration from the bottom of your handler file, after
main
:The first time a handler script is run, App Engine simply imports it, and this snippet runs your main in that situation. On subsequent requests, App Engine runs the
main
function, if you defined one.