GAE Python - 如何设置 cron 作业以启动后端任务 [英] GAE Python - How to set a cron job to launch a backend task

查看:31
本文介绍了GAE Python - 如何设置 cron 作业以启动后端任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 GAE 上运行每日报告任务,因为最近使用太多内存无法完成.因此,我想将其设置为后端任务.我已将后端设置如下:

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

在reporting.py 中定义了许多类,它们调用不同的报告.我的 cron.yaml 目前看起来像这样:

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

但从逻辑上讲,这只是通过 app.yaml 调用前端实例上的作业,当前看起来像这样:

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?

推荐答案

一种更简单的方法是将应用程序迁移到模块.此处解释:https://developers.google.com/appengine/docs/python/modules/

An easier way to do this is by migrating the app to modules. Explained here: https://developers.google.com/appengine/docs/python/modules/

这样做后,您只需在 cron.yaml 中添加以下行:

After doing so, you can just add following line in the cron.yaml:

target: yourmodule

这允许 cron 作业在 yourmodule.yaml 中定义的实例上运行

This allows the cron job to run on the instance defined in yourmodule.yaml

这篇关于GAE Python - 如何设置 cron 作业以启动后端任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆