Reputation: 173
I need help in implementing a simple cron job in GAE (python).
According to what I understood from appengine documentation, I made a file cron.yaml in the application root directory with the following content:
cron:
- description: blah blah
url: /crontask
schedule: every 1 minute
And my app.yaml file has the following content:
application: template-123
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: template-123.app
I made all my application code (cron and other parts) into a single file "template-123.py". In the code I implement cron in the following way:
class CronTask(Handler):
def post(self):
i=25
number = Birthday(day = i)
number.put()
And I tell the code to use this class for cron by stating: ('/crontask', CronTask).
However no new entries are uploaded to the datastore (as I believe they should be). And I know that it isn't a problem with the way I'm accessing the data store because when I try to do the same thing manually (upload entries to the data store in my non-cron part of application) it returns with appropriate results.
So I need some guidance as to what might I be doing wrong or missing? Do have to make some more changes to the yaml files or add some other libraries?
Upvotes: 3
Views: 6057
Reputation: 349
Cron uses GET, not POST. Change your def post(self)
to def get(self)
(or whatever else is appropriate).
Upvotes: 8
Reputation: 15143
Usually python files end in py. the handler should say
script: template-123.py
Test your cron job locally first. You should be able to access localhost:8000/_ah/admin, and click on the Cron Jobs link on the left. It should list all your cron jobs, and you should be able to test them with a link on the page. Debug on dev_appserver first.
Upvotes: 2