guerreiro
guerreiro

Reputation: 93

Error while deploying python in Google App Engine

I am trying to deploy a python application and I am receiving the following error message:

ERROR: (gcloud.app.deploy) Error Response: [4] Your deployment has failed to become healthy in the allotted time and therefore was rolled back. If you believe this was an error, try adjusting the 'app_start_timeout_sec' setting in the 'readiness_check' section.

My app.yaml is:

runtime: python
runtime_config:
  python_version: 3
env: flex
service: newservice
handlers:
- url: /
  script: hello.py

manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

I believe the problem is related to the yaml file, since I have deployed a sample application previously with no problems (using entrypoint on my yaml), then when I added a new python script and referred to it on the yaml file (using the handlers, to run my message block) I started to get this error.

Edit: after GAEFan's answer my hello has included a handler for readiness_check as:

def post():
    self.response.headers['Content-Type'] = 'application/json'   
    obj = {
      'status': 200, 
    } 
    self.response.out.write(json.dumps(obj))

webapp2.WSGIApplication([
    ('/readiness_check', post())
], debug=True)

Upvotes: 2

Views: 1679

Answers (2)

Dan Cornilescu
Dan Cornilescu

Reputation: 39814

You're running in a flexible environment app, the handlers configuration is a standard environment one. You need to use the entrypoint configuration for the flexible environment. From Application startup:

The runtime starts your application using the entrypoint defined in app.yaml. The entrypoint should start a process that responds to HTTP requests on the port defined by the environment variable PORT.

Without it your app is not really working and can't serve the health check requests.

Maybe useful: How to tell if a Google App Engine documentation page applies to the standard or the flexible environment

Upvotes: 1

GAEfan
GAEfan

Reputation: 11360

Readiness checks are enabled by default. So, you should set up url handlers for them. In this case, GAE is sending a request to /readiness_check, but your app.yaml doesn't have a handler for that url. Try this:

handlers:
- url: /.*
  script: hello.py

And make sure the url returns a 200 or similar response. To customize the readiness checking:

readiness_check:
  path: "/readiness_check"
  check_interval_sec: 5
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 2
  app_start_timeout_sec: 300

Or:

liveness_check:
  path: "/liveness_check"
  check_interval_sec: 30
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 2

Details at: https://cloud.google.com/appengine/docs/flexible/custom-runtimes/configuring-your-app-with-app-yaml#legacy_health_checks

Upvotes: 3

Related Questions