5

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 so. This file is in my main directory, alongside main.py, app.yaml, etc. As I understand it, I need to create a new file, cron.yaml which looks like this:

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

I'm not sure what I need to put in the url field. I'm also not sure if anything else is needed. Do I need to change my app.yaml file at all? Where do I specify the name of my parsexml.py file?

3 Answers 3

9

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This would also work fine if he added the cron handler to his existing WSGI app - in which case app.yaml would likely not need modifying.
2

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.

Comments

0

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

2 Comments

So I would put "url:/parsexml.py" ?
if that is the url in your app.yaml

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.