2016-06-19 2 views
2

Мой cronjob не работает, когда я нажмите кнопку Выполнить в http://localhost:8000/cronработает хрон в Google App Engine дает 404 ошибки

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

Ваш cron.yaml файл будет делать запросы к /tasks/summary.

Ваш app.yaml направляет их на ваш hello.application.

Но ваш соответствующий hello.py файл не имеет подходящего маршрута для /tasks/summary.

Вы можете расширить существующий шаблон маршрута, чтобы соответствовать этому пути:

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

Но более вероятно, что вы будете добавлять определенный маршрут для него (и вам нужно добавить код обработчика соответствия для него, а также):

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