简体   繁体   English

cron为什么会失败?

[英]Why does cron fail?

so I have these two cron jobs ( but as you can see from screens they fail, but I don't see any exception in the logs. ): 所以我有这两个cron作业(但是从屏幕上可以看到它们失败了,但是我在日志中看不到任何异常。): Cron失败

class AddTaskHandler(webapp2.RequestHandler):
def get(self):
    try:
        try:
            logging.info('trying to purge the queue')
            q = taskqueue.Queue('default')
            q.purge()
            logging.info('purge completed')
        except Exception as e:
            logging.error('Error in purging queue, continue., e: ' + e.message)
            pass

        logging.info('adding tasks to queue started')

        taskqueue.add(url = '/tasks/popularityUpdate')
        taskqueue.add(url = '/tasks/weatherUpdate')
        taskqueue.add(url = '/tasks/Recalculation')

        logging.info('adding tasks to queue finished')

        logging.info('Removing items from cache')
        memcache.delete_multi({'news1000', 'events1000', 'music1000', 'movies1000', 'theatre1000'})
        logging.info('Removing items from cache done.')

    except Exception as e:
        logging.error('Exception in adding tasks to the queue, e: ' + e.message)

    self.redirect('/')

Route handler: 路由处理程序:

app = webapp2.WSGIApplication([
    ('/', MainHandler),
    ('/cron/addtask', AddTaskHandler),
    ('/cron/refreshInfo', RefreshHandler),
   ], debug=True)
util.run_wsgi_app(app)

APP.YAML: APP.YAML:

application: **********
version: 3
runtime: python27
api_version: 1
threadsafe: no

handlers:
- url: /static
  static_dir: static

- url: /favicon\.ico
  static_files: static/img/favicon.ico
  upload: static/img/favicon\.ico

- url: /humans\.txt
  static_files: static/txt/humans.txt
  upload: static/txt/humans\.txt

- url: /robots\.txt
  static_files: static/txt/robots.txt
  upload: static/txt/robots\.txt

- url: /.*
  script: main.py

- url: /tasks/popularityUpdate
  script: main.py

- url: /tasks/Recalculation
  script: main.py

- url: /tasks/weatherUpdate
  script: main.py

- url: /cron/addtask
  script: main.py

- url: /cron/refreshInfo
  script: main.py

builtins:
- appstats: on

CRON.YAML: CRON.YAML:

cron:
- description: addTaskToTheQueue
  url: /cron/addtask
  schedule: every 3 hours

- description: refreshInformation
  url: /cron/refreshInfo
  schedule: every 24 hours

So my question is - what is the reason gae shows it as Failed ? 所以我的问题是-gae将其显示为“ 失败”的原因是什么?

  • Can you reach the urls that you add to the taskqueue (ie /tasks/popularityUpdate)? 您能否访问添加到任务队列的网址(即/ tasks / popularityUpdate)?
  • When you enter the cron job url manually, does it do what it suppose to? 当您手动输入cron作业url时,它是否可以执行预期的操作?
  • Doesn't the logs in the admin console show any errors (on the cron request)? 管理控制台中的日志是否没有显示任何错误(在cron请求中)?
  • Why do you have an redirect at the end of your cron-job handler ( AddTaskHandler )? 为什么在cron-job处理程序( AddTaskHandler )的末尾有重定向? Try removing it. 尝试将其删除。

..fredrik ..弗雷德里克

  1. You should put the catch-all handler (/.*) in the end of the handlers section in app.yaml. 您应该将包罗万象的处理程序(/.*)放在app.yaml中的处理程序部分的末尾。
  2. Test a basic /cron/addTask in the browser does it work? 在浏览器中测试一个基本的/ cron / addTask是否有效?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM