Skip to content

Instantly share code, notes, and snippets.

@rehbarkhan
Last active May 24, 2023 03:25
Show Gist options
  • Save rehbarkhan/5a126313d5ea9f17a9d90adafad1ee3d to your computer and use it in GitHub Desktop.
Save rehbarkhan/5a126313d5ea9f17a9d90adafad1ee3d to your computer and use it in GitHub Desktop.
Django Celery Task for Sendin Email
#1 define the cery on project foler.
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings') # can be copied from the wsgi file
app = Celery('proj')
app.auto_discovertask()
#2 define the actual method(mostly written in django)
def send_email(self):
email = EmailMSG(...)
#3 define the celery task to call the method
from celery.decorator import task
@task(name='send_email_task)
def send_email_task(email,...):
return send_email(email,...)
#4 call celerytask.delay() to execute the emthod
send_email_task.deplay(name,emial,...)
# 5 to start the task
celery -A proj worker -l info
@rehbarkhan
Copy link
Author

Django Celery Email send.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment