Reputation: 63
I'm trying to make a notification system that basically notifies the user or superuser when a specific action has been completed or a date has been reached.
Let's say I have a model which has a datetime field. I want my system to send me an email when that datetime is 5 day and 1 minute away from me and obviously applies to all the objects of that model. Or let's say I want to send that notification email on the moment of that date time. Also, I need this dynamic so I can change or remove the conditions of these notifications and perhaps have multiple notification conditions on the same model.
Now, I did consider scheduling tasks (I don't really know how to do that yet) but I thought that would really slow the system down on lets say hundreds of model objects, maybe even thousands.
My reason to come here and bother this amazing community with yet another question is that I want to know the following:
Is there an existing Django app that does this already but I couldn't find after hours of searching?
If not, is scheduling tasks the only option? If so, could a get a link to reference from? Although I'm guessing it might be bad to have way too tasks scheduled (again, I have no clue and I might as well be wrong). If that's the case, what do you amazing people suggest?
Thank you for your time reading this. I really appreciate this community.
Upvotes: 0
Views: 725
Reputation: 4827
You'll need to schedule the task. You can use django crontab for creating scheduled tasks (cron jobs). It's super easy to setup. You can run a cron job every minute to check the db for the datetimefield you care about and take the action you want. If you query your db correctly, it shouldn't be expensive but i will not recommend running a cron job every minute unless really required unless you have a dedicated server and you don't have to pay for execution time like in serverless environment.
SUMMARY
django-cron-tab
. django-celery-beat
.Django celery beat enables you to store the periodic task schedule in the database. The periodic tasks can be managed from the Django Admin interface, where you can create, edit and delete periodic tasks and how often they should run.
Upvotes: 0
Reputation: 114
i think what you want is not in django side, any way in pythonanywhere you can run a console app that run without stooping you can run with it everything you want they also have scheduling tasks you can set a time that run python file .
Upvotes: 1