-
Notifications
You must be signed in to change notification settings - Fork 19
/
tasks.py
55 lines (45 loc) · 1.51 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from celery import shared_task, signals
from django.core.mail import send_mail
@shared_task(ignore_result=True)
def task_mail():
subject = "celery subject test"
message = "celery message test"
recipient = ["xxxxxx@gmail.com", "xxxxxx@gmail.com", "xxxxxx@yahoo.com.tw"]
send_mail(
subject,
message,
"admin@celery_test.com",
recipient,
)
@shared_task(ignore_result=True, bind=True)
def task_mail_retry(self):
try:
if 1:
raise Exception()
subject = "celery subject test"
message = "celery message test"
recipient = ["xxxxxx@gmail.com", "xxxxxx@gmail.com", "xxxxxx@yahoo.com.tw"]
send_mail(
subject,
message,
"admin@celery_test.com",
recipient,
)
except Exception as e:
raise self.retry(exc=e, countdown=3)
@signals.task_prerun.connect
def prerun_task_mail(task_id, task, *args, **kwargs):
print(f"task_id: {task_id}, task: {task}")
print("prerun_task_mail ......")
@signals.task_postrun.connect
def postrun_task_mail(task_id, task, *args, **kwargs):
print(f"task_id: {task_id}, task: {task}")
print("postrun_task_mail ......")
@signals.task_success.connect
def success_task_mail(sender=None, **kwargs):
print(sender)
print("success_task_mail ......")
@signals.task_failure.connect
def failure_task_mail(task_id, exception, *args, **kwargs):
print(f"task_id: {task_id}, exception: {exception}")
print("failure_task_mail ......")