Sunil Lulla
Sunil Lulla

Reputation: 813

Threading for sending Notifications and Emails

I am developing a web application in django, on an update call activity i do the following things:

  1. Call my stored procedure to update the database.
  2. Generating data for notification.
  3. Sending actual notification to users.
  4. Generating email data for emails.
  5. Sending actual emails to the users.

The users can be more than one, i tested it for 50 users its giving slow response as there is too much processing in the call.

I am planning to implement a thread which will run in background and do steps 2,3,4 & 5 and my call return response after step 1.

I am confused whether am doing right or wrong.

Is there any good approach for doing it?

Upvotes: 1

Views: 216

Answers (1)

Bastian
Bastian

Reputation: 10433

I never have used threads for this kind of stuff ... and it may be problematic depending on which server you are running. (Are you running multiple instances? Will every instance start a thread? Some servers like uwsgi disable threading by default)

I usually use libraries like django-q (http://django-q.readthedocs.io/en/latest/) or celery (http://www.celeryproject.org/) to do sending email and other stuff that would delay requests.

If you are using uwsgi for serving your app, it has a simple feature for stuff like that: http://uwsgi-docs.readthedocs.io/en/latest/Mules.html

Upvotes: 1

Related Questions