2016-08-10 4 views
0

1分ごとにニュースアグリゲーターアプリを新しい記事に更新するためにcronジョブを作成しました。私は、GAEを実行している経験が非常に限られているため、私はcronジョブの完全な初心者だと言います。GAE pythonでcronジョブを実行する際に問題が発生しました

これは私のフォルダ構造です:

  • app.yamlを
  • テンプレート
    • news.py
    • index.yaml
    • feedparser.py
    • cron.yaml静的

    これはnews.pyに何である:

    cron: 
    - description: periodic update of news 
        url: /crontask 
        target: beta 
        schedule: every 1 minute 
    

    これはapp.yamlを次のとおりです:

    application: encoded-alpha-139800 
    version: 1 
    runtime: python27 
    api_version: 1 
    threadsafe: true 
    
    handlers: 
    - url: /static 
        static_dir: static 
    
    - url: /crontask 
        script: news.py 
    
    - url: /.* 
        script: news.app 
    
    libraries: 
    - name: jinja2 
        version: latest 
    

    display.html

    feed = ['https://news.google.co.in/news/section?cf=all&pz=1&ned=in&topic=e&ict=ln&output=rss&num=10'] 
    
    feedlist = [] 
    
    def render_str(template, **params): 
        t = jinja_env.get_template(template) 
        return t.render(params) 
    
    class CronTask(webapp2.RequestHandler): 
        def get(self): 
         self.redirect('/entertainment') 
    
    class MainPage(webapp2.RequestHandler): 
        def get(self): 
         self.response.write(render_str('mainpage.html')) 
    
    class Entertainment(webapp2.RequestHandler): 
        def get(self): 
         rssfeed = feedparser.parse(feed) 
         for news in rssfeed.entries: 
          new_entry = {'title': news.title, 'url': news.link, 'publisheddate': news.published} 
          feedlist.append(new_entry) 
         self.redirect('/1/display') 
    
    class Display(webapp2.RequestHandler): 
        def get(self, page_no): 
         is_this_last = False 
         list_to_be_displayed_here = feedlist[(int(page_no)-1)*5:int(page_no)*5] 
         try: 
          is_last = feedlist[int(page_no)*5] 
         except: 
          is_this_last = True 
         self.response.write(render_str('/display.html', page_no=page_no, feedlist=list_to_be_displayed_here, is_this_last=is_this_last)) 
    
    app = webapp2.WSGIApplication([('/', MainPage), 
              ('/entertainment', Entertainment), 
              ('/([0-9]+)/display', Display), 
              ('/crontask', CronTask) 
              ], debug = True) 
    

    私はこれが設定されるようになっているかcron.yamlであると仮定しますフィードの情報を表示するだけで、cursor()の実装方法はわかりませんでした方法、私はのDisplayに表示されている私は、feedlistをスライスして、基本的なページ番号を実装しました。

    私はnews.pyを実行すると、私はこのトレースバックを得る:私はcronジョブによってほぼ全体アプリケーションを実行しようとしているので、

    File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 83, in <module> 
    _run_file(__file__, globals()) 
        File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 79, in _run_file 
    execfile(_PATHS.script_file(script_name), globals_) 
        File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 1040, in <module> 
    main() 
        File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 1033, in main 
    dev_server.start(options) 
        File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 758, in start 
    options.config_paths, options.app_id) 
        File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 831, in __init__ 
    module_configuration = ModuleConfiguration(config_path, app_id) 
        File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 127, in __init__ 
    self._config_path) 
        File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 424, in _parse_configuration 
    config, files = appinfo_includes.ParseAndReturnIncludePaths(f) 
        File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\appinfo_includes.py", line 82, in ParseAndReturnIncludePaths 
    appyaml = appinfo.LoadSingleAppInfo(appinfo_file) 
        File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\appinfo.py", line 2190, in LoadSingleAppInfo 
    
    listener.Parse(app_info) 
        File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\yaml_listener.py", line 227, in Parse 
    self._HandleEvents(self._GenerateEventParameters(stream, loader_class)) 
        File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\yaml_listener.py", line 178, in _HandleEvents 
    raise yaml_errors.EventError(e, event_object) 
    google.appengine.api.yaml_errors.EventError: threadsafe cannot be enabled with CGI handler: news.py 
        in "C:\Users\IBM_ADMIN\Downloads\7c\NewsAggregatorGAE\app.yaml", line 19, column 18 
    

    はそれですか?または、私の設定やセットアップ全体に何か問題がありますか?

  • 答えて

    1

    問題は、あなたのapp.yamlファイルにCGIアプリであることをハンドラを示していることである:Request handlersから

    script: news.py 
    

    When App Engine receives a web request for your application, it calls the handler script that corresponds to the URL, as described in the application's app.yaml configuration file . The Python 2.7 runtime supports the WSGI standard and the CGI standard for backwards compatibility. WSGI is preferred, and some features of Python 2.7 do not work without it. The configuration of your application's script handlers determines whether a request is handled using WSGI or CGI.

    ...

    If you mark your application as thread-safe, concurrent requests will be enabled, which means that App Engine can dispatch multiple requests to each web server in parallel. To do so, set threadsafe: true in app.yaml. Concurrent requests are not available if any script handler uses CGI.

    ちょうどそれWSGIアプリ作ると、このエラーが行く必要があります離れて:

    script: news.app 
    

    GAE cronサービスは設定されたスケジュールに従って設定されたURLへのGETリクエストのジェネレータです。 Scheduling Tasks With Cron for Pythonから:あなたのアプリはcronジョブを実行する方法

    The App Engine Cron Service allows you to configure regularly scheduled tasks that operate at defined times or regular intervals. These tasks are commonly known as cron jobs. These cron jobs are automatically triggered by the App Engine Cron Service.

    ...

    A cron job invokes a URL, using an HTTP GET request, at a given time of day. An cron job request is subject to the same limits as those for push task queues.

    本当にそれは、これらの要求を処理する方法に帰着します。

    +0

    これは間違いを起こさなかった。しかし、それは自動的に実行されていないようです。私はサーバーを起動し、メインページに行き、リンクをクリックして '\ entertainment'に行きました。ニュースフィードが来ましたが、3分待ってからページが読み込まれず、新しいログ。 –

    +0

    開発サーバーでは、手動でトリガーする必要があります。管理ページの 'Cron Jobs'ページで' Run Now'をクリックしてください。 –

    +0

    それで 'cron.yaml'が管理サーバーにロードされていないようです。これは私が 'Cron Jobs'ページで取り上げるものです。' EventError:属性 'schedule''に1分ごとに値を割り当てることができません。 編集:ああ、私は "分"を指定する必要があると思います。 "分"。 –

    関連する問題