Actually the problem is very common. Let me describe this by example.
Imagine you have a web service where users register and pay for some gold status. There is expiration date. The question is how to remove the gold status in time?
I see at least two solutions:
- Write a daemon that checks user statuses and current time and perform some actions
- Use cron as a deamon and do the same
But I believe there are other approaches. By the way the language the system is written is Python but I don’t think this really matters.
4
Assuming you’re using a database to store account information, filtering a search on “account_expiry>=get_date()” on the database (i.e. in SQL) is a negligible operation.
If you’re not using a database for account information, your approach would vary based on what you’re using.
To answer your titled question, how do you run a deferred task on a backend in python, look at Celery
2
I believe there are two basic approaches:
- check the current status every time it’s necessary
- have a process run at some regular interval to do the checking
The problem with the first method is it can get resource intensive, while the problem with the second is that there may be a window where the user shouldn’t have the “gold status” but does.
For the second option whether you use cron or a custom deamon or a custom timed method in the program itself really makes no difference.
1