google-cloud-run

cloud run is closing the container even if my script is still running


I want to run a long-running job on cloud run. this task may execute more than 30 minutes and it mostly sends out API requests. cloud run stops executing after about 20 minutes and from the metrics, it looks like it did not identify that my task is still in the running state. so it probably thinks it is in idling and closing the container. I guess I can run calls to the server while job run to keep the container alive, but is there a way to signal from to container to cloud run that job is still active and not to close the container?

I can tell it is closing the container since the logs just stop. and then, the next call I make to the cloud run endpoint, I can see the "listening" log again from the NodeJS express.


Solution

  • I want to run a long-running job on cloud run.

    This is a red herring.

    On Cloud Run, there’s no guarantee that the same container will be used. It’s a best effort.

    While you don’t process requests, your CPU will be throttled to nearly 0, so what you’re trying to do right now (running a background task and trying to keep container alive by sending it requests) is not a great idea. Most likely your app model is not fit a for Cloud Run, I recommend other compute products that would let you run long-running processes as well.