Last active
May 24, 2023 03:25
-
-
Save rehbarkhan/5a126313d5ea9f17a9d90adafad1ee3d to your computer and use it in GitHub Desktop.
Django Celery Task for Sendin Email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Django Celery Email send.