I'm running a daily reporting task on GAE which since recently is using too much memory to finish. Therefore I'd like to set it as a backend task. I've set the backend as following:
backends:
- name: reporting
class: B4_1G
options: dynamic
start: reporting.app
In reporting.py there are a number of classes which are defined, which call different reports. My cron.yaml currently looks like this:
cron:
- description: update report 1
url: /reports/report1
schedule: every day 03:00
- description: update report 2
url: /reports/report2
schedule: every day 03:30
However logically this just calls the job on the frontend instance, through the app.yaml which currently looks like this:
application: appname
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /(robots\.txt)
static_files: \1
upload: (robots\.txt)
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /sitemap\.xml
static_files: sitemap.xml
upload: sitemap\.xml
- url: /images
static_dir: images
- url: /js
static_dir: js
- url: /css
static_dir: css
- url: /reports/.*
script: reporting.app
login: admin
What would I have to change to call these jobs on a backend instance on a daily basis?
An easier way to do this is by migrating the app to modules. Explained here: https://developers.google.com/appengine/docs/python/modules/
After doing so, you can just add following line in the cron.yaml:
This allows the cron job to run on the instance defined in yourmodule.yaml
Depends if you want a persistent or dynamic backend
For a dynamic one
The plan is:
A cron fires at specific time.
Adds a task on a queue that will start the backend
The backend starts
Example:
app.yaml:
backends.yaml:
crons.yaml:
queue.yaml:
On the startgooglepluscrawler.app you need to start the backend with a taskqueue:
And at the
backends/googlepluscrawler.py
just normally like an app, and a handler to/_ah/start
:The above example will fire up the backend instance.