`
hereson
  • 浏览: 1427739 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

GAE Cron Calling Backend

 
阅读更多

这是个配置Google App Engine,使之用Cron来调用Backends的范例。
为何要用Backends?
GAE限制前台Request的超时时间。而Backends没有此限制。
为何不总是用Backends?
用多了就不给免费了。另外据说启动时间也比较慢。
总之Backends适合那些需要长时间后台处理的任务。
Dynamic是什么?
Backends分为2种,一种是持续运行的,称为Resident;一种是被触发才运行的,称为Dynamic。这里给出的是Dynamic,是被Cron触发的。
This is only a sample of sending an email. It could be more customized.
For API and Parameters, 不解释.
For more details, move to the official document, please.

app.yaml:
---------------------------------------------------------
application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: false

handlers:
- url: /task
  script: webproxy.application
  login: admin
==============================
backends.yaml:
------------------------------------------------------------
backends:
- name: dm
  class: B1
  instances: 1
  options: dynamic
==============================
cron.yaml
------------------------------------------------------------
cron:
- description: test
  url: /task
  schedule: every day 00:00
  timezone: Asia/Shanghai
  target: dm
==============================
webproxy.py
------------------------------------------------------------
import webapp2
from google.appengine.api import mail

class MainHandler(webapp2.RequestHandler):
  def get(self):
    message = mail.EmailMessage(sender="Kira <Yagami@Light.com>", subject="gae mail from backends")
    message.to = "Law <L@M.N>"
    message.body = """
Introduction of Fake Note
"""
    message.send()
application = webapp2.WSGIApplication([('/task', MainHandler)],debug=True)
================================
Deploy Command:
For App Instance:
python appcfg.py update foldername/
For Backends Instance:
python appcfg.py backends foldername/ update
================================
How to manually call backends to debug?
In this case, it is triggered by requesting http://dm.myapp.appspot.com/task
Generally in the form of :
http://[backends name].[app name].appspot.com/[customized url path]
On exception raised, stack trace can be found in http response.
Logs are also permitted.
好吧,也许代码有些地方多此一举,我懒得尝试了。At least this works well on my app:)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics