GCP CRON作业失败,没有日志

时间:2018-04-05 19:25:03

标签: google-app-engine app-engine-flexible

我正在尝试在Google云端平台中设置CRON作业。该作业显示在GCP控制台中,尽管它失败了。没有日志可以揭示它失败的原因。该计划似乎工作正常,我可以手动运行该作业,但手动启动时也会失败。

如果我转到网址栏中的http://...../api/status/addit,则作业会按预期运行。

有一个链接到"查看日志"在任务队列页面上显示我的CRON作业,但当我转到那些日志时,它们完全是空的。

查看nginx请求日志不会显示对该URL发出的任何请求(或任何请求)。如果我手动转到工作的URL,我可以看到这些请求出现在日志中,并且应该发生的所有事情发生,所以我知道端点是好的。

Google App Engine灵活环境,Python 3

Flask API

我可以提供哪些其他信息?有很多活动的部分,我不想用不相关的信息来解决这个问题。

cron.yaml:

cron:
- description: 'test cron job'
  url: /api/status/addit
  schedule: every 1 minutes

端点:

< some Flask Blueprint stuff initiates the "status" blueprint so that this url will resolve to /api/status/addit >
...

@status.route('/addit')
def add_to_file():
    print('made it into the request')
    from flask import Response
    res = Response("{'foo':'bar'}", status=202, mimetype='application/json')
    return res

3 个答案:

答案 0 :(得分:2)

您的网址不匹配。尝试:

cron:
- description: 'test cron job'
  url: /addit
  schedule: every 1 minutes

答案 1 :(得分:2)

我在使用相同类型的配置(GAE flexible,Python 3)时遇到了相同的问题:

Cron失败,没有日志记录。


原来是防火墙问题:我的默认操作设置为 DENY

根据docs

  

注意:如果在灵活的环境中定义防火墙,则必须同时为10.0.0.1和0.1.0.1 IP地址设置防火墙规则,以允许您的应用程序接收来自Cron服务的请求。

10.0.0.10.1.0.1列入白名单解决了我的问题。

答案 2 :(得分:0)

当我使用SSL和脚本将用户从http重定向到https URL(在我的情况下为SSLify)时,遇到了类似的问题。 Google应用程序cron似乎使用http版本(至少对于我的flex应用程序而言),因此当cron调用我的应用程序时,它返回了302重定向到https版本,这被解释为错误。

“ cron作业将使用HTTP GET调用URL” https://cloud.google.com/appengine/docs/flexible/nodejs/scheduling-jobs-with-cron-yaml

感谢https://stackoverflow.com/a/53018498/4288232和评论,使我找到了解决方案。