Search code examples
pythongoogle-app-engine

Google App Engine to python3 migration for a specific service


I am deploying the following in sync.yaml. This was part of my python 2 project.

service: sync
instance_class: F2
automatic_scaling:
  max_instances: 1
runtime: python312
app_engine_apis: true

# taskqueue and cron tasks can access admin urls

handlers:
- url: /.*
  script: sync.app
  secure: always
  redirect_http_response_code: 301

env_variables:
  MEMCACHE_USE_CROSS_COMPATIBLE_PROTOCOL: "True"
  NDB_USE_CROSS_COMPATIBLE_PICKLE_PROTOCOL: "True"
  DEFERRED_USE_CROSS_COMPATIBLE_PICKLE_PROTOCOL: "True"
  CURRENT_VERSION_TIMESTAMP: "1677721600" 

The handlers are defined in a file called sync.py. Will this handler call my python script called sync.py despite the reference saying sync.app?

The reason I'm asking is because when I call the urls referenced for sync, as specified by having the prefix 'sync' in the host name, I'm getting errors that lead me to believe it is calling main.py as specified in apps.yaml.

This pattern was working in python 2.

The url in question is https://sync-dot-project1.appspot.com/, i expect this to be handled by the service.

However, I suspect it is being handled by the default service as specified in app.yaml/main.py because it is redirecting to a "trusted site" ? which is one of the first operations in main.py https://project1.appspot.com/


Solution

    1. According to documentation for app.yaml for python 3,

    script:
    Optional. Specifies that requests to the specific handler should target your app. The only accepted value for the script element is auto because all traffic is served using the entrypoint command...

    1. This means that script: sync.app isn't telling Google to call sync.py (that command is being ignored).

    2. To tell Google to call sync.py (given that this isn't your default service), sync.py should have it's own app object and then you should have the following in sync.yaml

      entrypoint: gunicorn -b :$PORT sync:app 
      
      
    3. The above line starts a web server in sync.py and will then call the handlers for the different routes in that file.