I have a Dash App running in a GCP Cloud Run container. This is a data dashboard that makes calls back to a GCP Postgres instance to update data that refreshes every 30 min. If the app is being access often the I believe the container stays refreshed and allows the for the app to refresh quickly. However when its is accessed often the container is not making the database calls and refreshing the data. How can I periodically have the GCP Cloud Run container run functions in the code and query new data?
Thanks,
Eric
Hi @tangedahl,
It seems you're encountering a scenario where your Cloud Run container, designed to refresh data every 30 minutes, isn't consistently making database calls when the app isn't accessed frequently. This is likely due to Cloud Run's autoscaling behavior, which can scale down to zero instances when there's no traffic. To resolve this, you can implement a cron-like task scheduler that triggers certain functions at regular intervals, such as querying new data from your GCP Postgres instance every 30 minutes, even when the app is not actively being accessed. Here's how you can achieve that:
I hope this helps!
Ok I got most of this setup, first question however is don't I want a Pub/Sub endpoint, not an HTTP?
I have a topic created, I set a eventarc trigger in the Google Cloud run app setting which points to that topic, then I have a scheduler setup to to run that topic periodically.
This is code running in my cloud run app: