Django/Python email notification for events - python

I work on a page in Django, where users can set custom reminders for different dates (max. 3 per date). The reminders should send via e-mail. Its similar to Google Calendar, where you can set multiple reminders for each event in x-minutes, x-hour or x-days before the date starts.
I wonder, how I can solve it combined with Django. Since there will be a lot of users and dates, which should of course also run perfomant.
Should I do this with a cron job? Is there a python way?

The other traditional way is to use django-celery: http://pypi.python.org/pypi/django-celery/
You can use the celerybeat command to run periodical tasks. Also you can start pending tasks from a django view.

You can use a cron job. To create a management command: refer to the documentation here
Also, you can create the email generation as a queue based, distributed implementation for enhanced performance. You can use Django-mailer app for the same.

Related

Schedule emails on a specific time using Django and celery

This is the use case I am looking for :
User will register on my application
It is a note making and remainder application
While creating remainder users will enter the time my application wants to send user an email at that time
I have to use celery for the same
I read several posts and stack overflow answers but didn't get proper answer for the same.
My application is written in Django.
When a user creates a new reminder just schedule a send email task in celery. Note that this is a simple solution but it will make it hard for the user to change notification time after creating it.
From this answer:
To execute a task at a specified date and time you can use eta attribute of apply_async while calling task as mentioned in docs
your_task.apply_async(kwargs={}, eta="your_send_time")
A different solution is to have a task running every 1 minute which will check in DB if there are any emails to be sent. You don't have to use Celery for that. Cron-like lib should do the trick. For example schedule lib or django-cron or Django Commands
Edit: this guy says you should not use dbader/schedule with Django.

Django how best to perform api request for large jobs

I need some direction as to how to achieve the following functionality using Django.
I want my application to enable multiple users to submit jobs to make calls to an API.
Each user job will require multiple API calls and will store the results in a db or a file.
Each user should be able to submit multiple jobs.
In case of some failure such as network blocked or API not returning results I want the application to pause for a while and then resume completing that job.
Basically want the application to pickup from where it was left off.
Any ideas as to how I could implement this solution or any technologies such as celery I should be looking at or even if you can suggest an opensource project where I can learn how to perform this would be a great help.
You can do this with rabbitmq and celery.
This post might be helpful.
https://medium.com/#ffreitasalves/executing-time-consuming-tasks-asynchronously-with-django-and-celery-8578eebab356

Django Auth Issues

Ive been configuring and troubleshooting some Django auth issues with a custom backend.
One thing I have noticed is that once the expiry date has expired for the session (confirmed via a Session.objects.all()) that the session remains in the table.
At the point that I have to reauthenticate it creates another entry creating a situation where a single user can have tons of sessions within the table rather then just one.
Is there a simple way of getting Django to clear these out at the point of them expiring ?
Thanks,
From official documentation -
Django does not provide automatic purging of expired sessions. Therefore, it’s your job to purge expired sessions on a regular basis. Django provides a clean-up management command for this purpose: clearsessions. It’s recommended to call this command on a regular basis, for example as a daily cron job.
Use something like this:
python manage.py clearsessions
...and schedule it to run regularly.

cron tab (or celery, whichever is best) - best way to register for certain days

I want to implement a reminder system, where a reminder email will be sent to the users based on some date field in their userprofile.How can I implement this ? Many suggested me not to use celery. Told me to use cron tab.
This is how I do, is this good way? If not, please suggest me a good way.
If cron:
Planning to run a python management command daily, that will check if there is some reminder for that day, by checking dates of all the users.
I dont think this is good, I think, whenever the user select their reminder date, then that date will be registered some how and job will be run only on that date, but I am not getting how to implement this.
Way I know to implement this:
Create a database table named 'reminderdates', and whenever a reminder is registered, add that date and user_id to that table. So, run a cron job everyday that checks if that day is among the dates in the table. If yes job will be run. Also, I will run another cron job that will delete all the older reminderdates from the table so the table size wont get increased with time.
The simplest solution is to setup a cron job to hit a URL on the site that performs the task. I would recommend Celery though. Here's why (from Django/Celery Quickstart):
Cron has the advantage of simplicity, but it's not not ideal for the job. You have to take steps to ensure that regular users of the site cannot hit those URLs directly. It also forces you to manage an external configuration. What if you forget to perform the configuration on the qa or production servers? It would be safer and easier if the configuration was in the code for the site.
You will find a tutorial on how to implement tasks with celery on that previous link.
As for your reminderdates table idea, it should work. You can simplify it a little bit if you try this:
Adding a column with a sent status. Your task will check for date and sent status. If current day matches reminder date AND status is "unsent", then send the reminder.
You don't need a secondary cron job to delete older reminders. The same task that sends the reminders can send each one and delete it after (in which case the sent/unsent status would not be needed).

automatic page update appengine

I have an application that uses Python appengine, there is a service that updates the status of users, if an admin person has a page open, I would need it to update in real time. I know that appengine has CRON and task queues, what would be the correct way to handle this? Should I set an update flag in the models that that triggers jscript?
The Channel API can be used to send real-time(ish) data to clients, without the need of clients polling the server.

Categories

Resources