在此示例代碼的應用程序的URL似乎是由在應用內這條線來確定:在本例中,main.py或app.yaml是否確定App Engine cron任務使用的URL?
application = webapp.WSGIApplication([('/mailjob', MailJob)], debug=True)
而且通過app.yaml中的應用處理程序中這一行:
- url: /.*
script: main.py
url: /tasks/summary
所以似乎cron實用程序將調用「/tasks/summary
」而且由於應用H:然而,定期任務的URL被該行設定安德勒,這將導致main.py
被調用。這是否意味着,只要cron是而言,在設置URL應用該行無關:
application = webapp.WSGIApplication([('/mailjob', MailJob)], debug=True)
。 。 。因爲cron任務所需的唯一URL是在app.yaml中定義的。
app.yaml
application: yourappname
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: main.py
cron.yaml
cron:
- description: daily mailing job
url: /tasks/summary
schedule: every 24 hours
main.py
#!/usr/bin/env python
import cgi
from google.appengine.ext import webapp
from google.appengine.api import mail
from google.appengine.api import urlfetch
class MailJob(webapp.RequestHandler):
def get(self):
# Call your website using URL Fetch service ...
url = "http://www.yoursite.com/page_or_service"
result = urlfetch.fetch(url)
if result.status_code == 200:
doSomethingWithResult(result.content)
# Send emails using Mail service ...
mail.send_mail(sender="[email protected]",
to="[email protected]",
subject="Your account on YourSite.com has expired",
body="Bla bla bla ...")
return
application = webapp.WSGIApplication([
('/mailjob', MailJob)], debug=True)
def main():
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
足夠的上下文不添加URL提供了依據。你正在胡思亂想,不必要的大驚小怪。 – 2009-07-12 00:06:34