Cron工作-响应404

时间:2018-12-14 09:03:11

标签: google-app-engine cron google-cloud-platform http-status-code-404 google-cloud-functions

几天前,我在Google App Engine上的cron作业停止了工作。 它响应404代码。 很奇怪,因为我没有更改yaml文件,并且可以正常工作。

感谢您的帮助。谢谢!

cron.yaml

cron:
- description: Push a "tick" onto pubsub every 5 minutes
  url: /publish/minutes-5-tick
  schedule: every 5 minutes

- description: Push a "tick" onto pubsub every hour
  url: /publish/hourly-tick
  schedule: every 1 hours

- description: Push a "tick" onto pubsub every hour
  url: /publish/hourly-tick-2
  schedule: every 1 hours

- description: Push a "tick" onto pubsub every day
  url: /publish/daily-tick
  schedule: every 24 hours

- description: Push a "tick" onto pubsub every week
  url: /publish/weekly-tick
  schedule: every saturday 00:00

app.yaml

runtime: python27
api_version: 1
threadsafe: true

handlers:

# Handler for the pubsub cron.
- url: /publish/.*
  script: main.app
  login: admin
  secure: always

- url: /.*
  script: main.app

libraries:
- name: webapp2
  version: latest
- name: pycrypto
  version: latest
- name: ssl
  version: latest

instance_class: F1

main.py


    class PushToPubSub(webapp2.RequestHandler):
        def get(self, topic):
            pubsub_utils.publish_to_topic(topic, str(time.time()))

            self.response.headers['Content-Type'] = 'application/json'
            self.response.write(json.dumps({"status": "200"}))

    app = webapp2.WSGIApplication([
        webapp2.Route(r'/publish/', handler=PushToPubSub)
    ], debug=True)

Log:

2 个答案:

答案 0 :(得分:1)

您没有/publish/hourly-tick的网址处理程序。试试:

webapp2.Route(r'/publish/<topic:\w+>', handler=PushToPubSub),

这将发送“小时刻度”作为要在PushToPubSub中处理的主题

答案 1 :(得分:0)

解决方案是此处所述的重做步骤 https://github.com/FirebaseExtended/functions-cron

谢谢。