2

I came across google app engine a week ago and wanted to play around with it a bit. I wrote a dummy application which checks a url and based on the return code it logs to a file if the site is "up" or "down"

I wanted to deploy it on to app engine and schedule cron jobs ( for example every one minute). I came across this example. I complete understand the app.yaml file but I am not sure about the 'url' int he cron.yaml file. WHat it is purpose? can it be skipped in the file?

Morover the example uses the webapp2 module. Do I wrap my code in that module?

Code given below:

import requests
import logging

logger = logging.getLogger('testapp')
hdlr = logging.FileHandler('/Users/me/Desktop/testlog.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr) 
logger.setLevel(logging.INFO)

try:
    r = requests.head("http://www.redcafe.com")
    code = (r.status_code)
except requests.ConnectionError:
    logger.error('URL Error')

if code == 200:
    logger.info('Up and running')
else:
    logger.error('Cant find website')

1 Answer 1

1

According to the cron.yaml doc:

The url field specifies a URL in your application that will be invoked by the Cron Service.

Basically your app will register a handler for that URL which will be invoked when the GAE cron service requests it.

You probably want to spend some time getting familiar at least with:

Using the requests library in GAE may be tricky: Can Python Requests library be used on Google App Engine? You may want to take a look at the GAE sockets or URL fetch services as alternatives.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.