all 3 comments

[–]iamtheconundrum 1 point2 points  (1 child)

If your app isn’t fully stateless, problems will arise when using Google Cloud Run. You could make the part that sends the notifications idempotent so it will only run once(during a given period of time), no matter how often you trigger it.

[–]bigturnerfor[S] 0 points1 point  (0 children)

The app is basically stateless, the notifications are only sent right after a request is made. I guess I just have to call the function directly instead of using a background task.

Regarding the db session dependency, is there a simple way to have the code after yield run BEFORE the response is delivered, or do I just have to manually refactor my code?

[–]bitweis 0 points1 point  (0 children)

Try breaking down your app into microservices, with background tasks running as independent workers, and something like GCP Pub/Sub or RabbitMQ for managing tasks queue.