Setting up cron job in google app engine python

后端 未结 3 1686
别跟我提以往
别跟我提以往 2021-02-06 14:12

I\'m just getting started with Google App Engine so I\'m still learning how to configure everything. I wrote a script called parsexml.py that I want to run every 10 minutes or s

3条回答
  •  感动是毒
    2021-02-06 15:05

    Brian,

    You'll need to update both your app.yaml and cron.yaml files. In each of these, you'll need to specify the path where the script will run.

    app.yaml:

    handlers:
    - url: /path/to/cron
      script: parsexml.py
    

    or if you have a catch all handler you won't need to change it. For example:

    handlers:
    - url: /.*
      script: parsexml.py
    

    cron.yaml:

    cron:
    - description: scrape xml
      url: /path/to/cron
      schedule: every 10 minutes
    

    As in the documentation, in parsexml.py you'll need to specify a handler for /path/to/cron and register it with a WSGI handler (or you could use CGI):

    from google.appengine.ext import webapp
    from google.appengine.ext.webapp.util import run_wsgi_app
    
    class ParseXMLHandler(webapp.RequestHandler):
        def get(self):
            # do something
    
    application = webapp.WSGIApplication([('/path/to/cron', ParseXMLHandler)],
                                         debug=True)
    if __name__ == '__main__':
        run_wsgi_app(application)
    

    Note: If you are using the Python 2.7 runtime, you will want to specify script: parsexml.application where application is a global WSGI variable for handling requests.

提交回复
热议问题