When a request triggers a cloud run via a http request, I want to immediately respond with a success and in background make third party API calls on a paginated set of data from my database, this background task might take anywhere between 5 to 20 minutes to complete, is there a way to keep the cloudrun instance active until this background task completes?
I do know about always on CPU, but would it scale down the instance once the background task complete or will it keep the instance always on?
I do not want to set minimum instances as I do not need any instance to be unnecessarily active once my background task is complete
Is this possible with cloud run?
Hello @abhaychandavar ,
Welcome to the Google Cloud Community!
Although CPU resources are continuously allocated, Cloud Run's autoscaling functionality remains active. It may terminate container instances if they are not needed to handle incoming traffic. An instance will not remain idle for more than 15 minutes after processing a request unless it is kept active by setting a minimum number of instances.
To ensure idle instances are always available, one approach is to set your min-instance value to more than 1, although it appears you prefer not to set a minimum instance.
Alternatively, you can use Pub/Sub to trigger a Cloud Function or another Cloud Run service dedicated to processing background tasks. When the initial Cloud Run service receives an HTTP request, it can publish a message to a Pub/Sub topic, including details necessary for the background task. A Cloud Function or another Cloud Run service subscribed to this topic can then process the message and execute the long-running task. This arrangement allows the initial Cloud Run instance to terminate after responding to the HTTP request, while the background task continues independently.
I also have the same query, I want the "Always ON CPU", Cause I am publishing social media posts, And the speed I get while downloading the post media files is very slow in Cloud Run service.
My NodeJS server in the Cloud Run, Always return the response to the Http request after completing it's job.
But the issue is, If I keep the CPU always on, Will it still bill me until the next 15 minutes, After the http request is responded, And if it'll bill, How do I prevent it, I want to set the concurrency to 1, So the instance should just terminate after the http request is responded, So how do I do that?