Search code examples
pythoncrongoogle-cloud-functionsgoogle-cloud-scheduler

Triggering actions in Python Flask via cron or similar


I'm needing to trigger an action at a particular date/time either in python or by another service.

Let's say I have built an application that stores the expiry dates of memberships in a database. I'm needing to trigger a number of actions when the member expires (for example, changing the status of the membership and sending an expiry email to the member), which is fine - I can deal with the actions.

However, what I am having trouble with is how do I get these actions to trigger when the expiry date is reached? Are there any concepts or best practices that I should stick to when doing this?

Currently, I've achieved this by executing a Google Cloud Function every day (via Google Cloud Scheduler) which checks if the membership expiry is equal to today, and completes the action if it is. I feel like this solution is quite 'hacky'.


Solution

  • I'm not sure which database you are using but I'm inferring you have a table that have the "membership" details of all your users. And each day you run a Cron job that queries this table to see which row has "expiration_date = today", is that correct?.

    I believe that's an efficient way to do it (it will be faster if you have few columns on that table).