2011-05-09 2 views
3

저는 Google App Engine에서 cron Python 스크립트를 실행하기 위해 며칠 동안 노력했습니다.이 스크립트는 단순히 내 서버에서 호스팅되는 스크립트를 실행합니다.Google App Engine Python Cron

페이지에 데이터를 게시 할 필요없이 간단히 연결을 열고 완료 될 때까지 기다렸다가 이메일을 보내십시오.

이전에 작성한 코드는 "성공"으로 기록되었지만 전자 메일을받지 못했고 테스트를 위해 추가 한 logging.info 코드가 없었습니다.

아이디어가 있으십니까?

원래 과 내가 원래 작성한 잘못된 코드는Google AppEngine Python Cron job urllib에서 찾을 수 있습니다. - 그저 내가 전에 시도한 것을 알고 있습니다.

+0

이전 질문과 정확히 일치하지 않습니까? –

+0

아니요, 실제로 Cron 작업을 실행하지 않았기 때문에 실제로 실행 중인지 "성공"이라고 말할 로그를 얻었습니다. 그러나 아무 것도하지 않았습니다. – James

+0

코드가 어떻게 바뀌 었습니까? 새로운 코드를 보여주세요! 또한 브라우저에서 직접 스크립트를 실행하면 어떻게됩니까? –

답변

4

이상한 것들이 여기에서 발생했습니다.

handlers: 
- url: /cron 
    script: assets/backup/main.py 

- url:/
    static_files: assets/index.html 
    upload: assets/index.html 

그렇지 않으면 내가 파일을 찾을 수 없다는 미친 오류를 얻을 것 : 루트가 설정되기 전에

첫째, app.yaml 나는 나의 /cron 핸들러를 배치했다. 그 비트는 실제로 의미가 있습니다.

다음 비트는 파이썬 코드입니다. 확실하지 여기에 무슨했지만 결국 나는이 작업을 수행하여 작업 얻을 관리 있었는지 : 그것은 문제를 일으키는 무엇이든

#!/usr/bin/env python 
# import logging 
from google.appengine.ext import webapp 
from google.appengine.api import mail 
from google.appengine.ext.webapp.util import run_wsgi_app 
from google.appengine.api import urlfetch 

import logging 

class CronMailer(webapp.RequestHandler): 
    def get(self): 
     logging.info("Backups: Started!") 
     urlStr = "http://example.com/file.php" 

     rpc = urlfetch.create_rpc() 
     urlfetch.make_fetch_call(rpc, urlStr) 
     mail.send_mail(sender="[email protected]", 
      to="[email protected]", 
      subject="Backups complete!", 
      body="Daily backups have been completed!") 
     logging.info("Backups: Finished!") 

application = webapp.WSGIApplication([('/cron', CronMailer)],debug=True) 
def main(): 
    run_wsgi_app(application) 

if __name__ == '__main__': 
    main() 

은, 지금은 고정입니다.