Search code examples
pythonnode.jsgoogle-cloud-platformgoogle-app-engine

GAE: Submit task from one service to be executed by another service


I have a GAE app with a Python3 service (the default) and a NodeJS18 service.

I currently submit App Engine tasks (not HTTP target tasks) from the Python3 service and those tasks are executed by that same Python3 service. I have a default task queue where those tasks are submitted.

Now, I would like to submit a task from the Python3 service and have it executed by the NodeJS18 service.

I'm using the google.cloud.tasks_v2 Python client to submit tasks. You can select the queue to submit the task to, but I don't see a way to specify which GAE service should process the task. Is it possible to specify the service to process the task?

If I instead submit the task from the NodeJS18 service to the same default queue, will it then be executed by the NodeJS18 service?


Solution

  • I don't see any mention of 'service' in the documentation.

    Given that you have to specify the relative_uri (this is the route that will handle the task), I think the following are possible ways to achieve your aim

    1. If your dispatch.yaml file only routes based on paths (no domain is mentioned), then I think that just specifying the path as the value for the relative_uri should get it routed to the correct service.

      • e.g you have
          - url: "*/mobile/*"
           service: mobile-frontend
      
          - url: "*/work/*"
           service: static-backend
      
      

      I think that if you just specify /mobile/mobile_task as the relative_uri for the task when being called from /work/page-1, it should get routed to the mobile-frontend service.

    [NOTE: Haven't tried this option myself]

    1. If your dispatch.yaml file routing includes domains/subdomains, then you could possibly first execute an HTTP call (e.g a POST) to the url of the target service (at a specific route) and that route will then submit the task e.g.

      • Say you have a service reached at blog.example.com. This is the service you wish to process a task submitted from your default service
      • From a different (default) service, you make an HTTP call to blog.example.com/prep_task_invocation/ and pass the data for the task to be executed
      • blog.example.com/prep_task_invocation/ will then submit the task to itself (the current process you have) assuming the relative_uri won't get it routed to another service