GAE Python - 如何设置cron作业以启动后端任务 [英] GAE Python - How to set a cron job to launch a backend task
问题描述
我在GAE上执行每日报告任务,因为最近使用的内存太多。因此,我想将其设置为后端任务。我已设置后端如下:
后端:
- name:reporting
class:B4_1G
选项:dynamic
start:reporting.app
是定义的多个类,它们调用不同的报告。我的cron.yaml目前看起来像这样:
cron:
- description:update report 1
url :/ reports / report1
日程安排:每天03:00
- 描述:更新报告2
url:/ reports / report2
日程安排:每天03:30 $ b $但是在逻辑上,这只是通过app.yaml调用前端实例上的作业,目前看起来像这样: / p>
application:appname
version:1
runtime:python27
api_version:1
threadsafe:true
处理程序:
- url:/(robots\.txt)
static_files:\1
上传:(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
我需要更改什么才能在后端实例上每天调用这些作业?
解决方案更简单的方法是将应用程序迁移到模块。此处解释: https://developers.google.com/appengine/docs/python/modules /
这样做后,您可以在cron.yaml中添加以下行:
target:yourmodule
在yourmodule.yaml
中定义的实例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:
target: yourmodule
This allows the cron job to run on the instance defined in yourmodule.yaml
这篇关于GAE Python - 如何设置cron作业以启动后端任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!