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
In GAE, all actions are done via URLs. You can't just run an arbitrary script as a cron: you need to make that script a handler and give it a URL, like any other view in your project.
So, map a URL to your script in app.yaml, edit the script to make it a handler, and use that URL in cron.yaml.
The url is used to run the py script for your cron job
basically in your app.yaml
you have
app.yaml
handlers:
- url: /helloworld.py
script: helloworld.py
in cron.yaml
cron.yaml
- description: scrape xml
url: /helloworld.py
schedule: every 10 minutes
if you want the cron to run hello world you have to set the url as url: /helloworld.py
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.