Skip to content

Integrating πŸ”— Celery with Django via Redis server ,To-Do asynchronously πŸ‘€task without stopping the main-flow πŸ“ƒ of Django-project . It increase your speed πŸš€ and user experience 🀡 of website

Developer-R-7/Celery-Integration-Django

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Integarting Celery with Django to asynchronous tasks πŸ“ƒ

Integrating πŸ”— Celery with Django via Redis server ,To-Do asynchronously πŸ‘€task without stopping the main-flow πŸ“ƒ of Django-project .It increase your speed πŸš€ and user experience 🀡 of website . This repo explain how to setup Celery,and integrate it with the Django-Framework.

Note : Steps to steup Celery on production-side is different

🏁 Reference link to setup Celery on production side

Approach 🏁

Celery package help us to asynchronous tasks on different worker πŸ–₯️ ,That is on Redis server. The Celery also have some great features in scheduling πŸ• task after a certain period of time. The tasks are excuted on different server (Redis server), and are not run on Django-Server.If we run long and complicated tasks on django server it will reduced the efficiency of website


Modern users expect pages to load instantaneously ⚑, to solve this we consider many solutions like multiprocessing, multithreading 🧡, asynchronous functions using async/await or the Message Queues.


Installation/Dependencies πŸ’Ύ

Use the package manager pip to install the following modules and packages.

pip install -r requirements.txt

Usage πŸ”­

Open terminal and write following commands πŸ“

To run Celery worker

celery -A your_django_project_name.celery worker --pool=solo -l info

And in separate terminal run django server

python manage.py runserver

Updating SMTP settings for sending mails πŸ“¨

Change the settings for the sender-mail credential in the settings.py file , enter the sender mail and sender mail-password (SMTP configuartion)

Making tasks πŸ“–

Task are python functions which can be called in the django-project and also be scheduled at particular time. Task-function can be written in task.py file and can be imported anywhere in the project

@task()
def Send_Mail_With_Celery(email):
  your function goes here....
  return "done"

calling function

Send_Mail_With_Celery.delay(args)

Purpose πŸ“’

Increase Speed ⚑ and User-experience of website

Sending mail using Celery πŸ‘€

Sending mail without using Celery βŒ›

NOTE the difference : Celery does not stoped the next page from loading and done the task on worker whereas Without using Celery it took almost 3 seconds βŒ› , to load next page

This is just a small-function but imagine making operations on large user-database ,it would be not good ☹️

Reference πŸ”—

Setup Celery in Django to asynchronous tasks

Contributing 🀡

Pull requests are welcome πŸ–€. For major changes, please open an issue first to discuss what you would like to change.

About

Integrating πŸ”— Celery with Django via Redis server ,To-Do asynchronously πŸ‘€task without stopping the main-flow πŸ“ƒ of Django-project . It increase your speed πŸš€ and user experience 🀡 of website

Topics

Resources

Stars

Watchers

Forks