在谷歌应用引擎中运行cron会出现404错误

时间:2016-06-19 04:46:12

标签: python-2.7 google-app-engine cron

点击http://localhost:8000/cron

中的“立即运行”时,我的cronjob无法运行

404 error screenshot

我的应用包含以下文件 hello.py

import webapp2

class MainPage(webapp2.RequestHandler):

    def get(self):
        self.response.headers["Content-Type"] = "text/plain"\
        self.response.write("Congratulations, it's a web app!")

    routes = [('/', MainPage)]
    my_app = webapp2.WSGIApplication(routes, debug=True)

的app.yaml

application: hello
version: 1
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /.*
  script: hello.my_app

- url: /tasks/summary
  script: hello.application

cron_script.py

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class CronTask(webapp.RequestHandler):
    def get(self):
        f = open("test.txt","w") #opens file with name of "test.txt"
        f.write("I am a test file.")
        f.write("Maybe someday, he will promote me to a real file.")
        f.write("Man, I long to be a real file")
        f.write("and hang out with all my new real file friends.")
        f.close()

application = webapp.WSGIApplication([('/tasks/summary', CronTask)],
                                 debug=True)
if __name__ == '__main__':
    run_wsgi_app(application)

cron.yaml

cron:
- description: daily summary job
  url: /tasks/summary
  target: beta
  schedule: every 1 minutes

1 个答案:

答案 0 :(得分:1)

您的cron.yaml文件会向/tasks/summary提出请求。

您的app.yaml会将他们引导至您的hello.application

但您的匹配hello.py文件没有/tasks/summary的匹配路由。

您可以扩展现有路线模式以匹配该路径:

routes = [('/.*', MainPage)]

但更有可能你会为它添加特定的路由(你还需要为它添加匹配的处理程序代码):

routes = [('/tasks/summary', CronHandler)]