2009-07-11 3 views
1

アプリのURLは、アプリ内でこの行によって決定されるようだ:この例では、main.pyまたはapp.yamlによってApp Engineのcronタスクで使用されるURLが決まりますか?このサンプルコードで

application = webapp.WSGIApplication([('/mailjob', MailJob)], debug=True) 

もこのラインでのapp.yamlのアプリハンドラ内:

- url: /.* 
    script: main.py 

だから、cronユーティリティは、「/tasks/summary」と呼ぶようだと理由アプリhの

url: /tasks/summary 

:しかし、クーロンタスクのURLは、このラインで設定されていますandlerを実行すると、main.pyが呼び出されます。これは、cronに関する限り、URLを設定するアプリ内の行が無関係であることを意味しますか?

application = webapp.WSGIApplication([('/mailjob', MailJob)], debug=True) 

。 。 cronタスクで必要とされる唯一のURLはapp.yamlで定義されたURLなので

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() 

答えて

3

あなたはこのようにそれを行うことができます:

app.yaml 
application: yourappname 
version: 1 
runtime: python 
api_version: 1 

handlers: 

- url: /tasks/.* 
    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([ 
     ('/tasks/summary', MailJob)], debug=True) 

def main(): 
    wsgiref.handlers.CGIHandler().run(application) 

if __name__ == '__main__': 
    main() 
1

this pageのように見えます(ただし、私たちにURLを教えてください)。設定とコードは正常に実行されません:cronタスクはURL path/tasks/summaryにアクセスしようとしますが、app.yamlはmain.pyを実行しますが、後者は/ mailjobのハンドラを設定するだけですcronタスクの試行は404ステータスコードで失敗します。

+0

十分なコンテキストはURLを追加することなく、提供されました。あなたは気難しく、不必要な大騒ぎをしています。 –

+2

@David、URLは助けになりました - コード&設定が本当に不完全であることを確認するために検索する必要がありましたので、タイトルに載っている質問への答えは "このmain.py norこのapp.yamlは、そのURLを提供するためにどのコードを実行すべきかを定義します(つまり、このコードと設定ファイルのセットは正常に実行されません)。 –

関連する問題