diff --git a/apps/wf/tasks.py b/apps/wf/tasks.py index b6304470..020bc954 100644 --- a/apps/wf/tasks.py +++ b/apps/wf/tasks.py @@ -10,9 +10,19 @@ from celery import shared_task from apps.wf.models import State, Ticket, TicketFlow, Transition import time from apps.utils.tasks import send_mail_task +from channels.layers import get_channel_layer +from asgiref.sync import async_to_sync myLogger = logging.getLogger('log') +@shared_task(base=CustomTask) +def ticket_push(userId): + channel_layer = get_channel_layer() + data = { + 'type': 'ticket', + 'msg': '' + } + async_to_sync(channel_layer.group_send)(f"user_{userId}", data) @shared_task(base=CustomTask) def send_ticket_notice(ticket_id): @@ -23,13 +33,16 @@ def send_ticket_notice(ticket_id): params = {'workflow': ticket.workflow.name, 'state': ticket.state.name} if ticket: if ticket.participant_type == 1: + # ws推送 # 发送短信通知 pt = User.objects.filter(id=ticket.participant).first() + ticket_push.delay(pt.id) if pt and pt.phone: send_sms(pt.phone, 1002, params) elif ticket.participant_type == 2: pts = User.objects.filter(id__in=ticket.participant) for i in pts: + ticket_push.delay(pt.id) if i.phone: send_sms(i.phone, 1002, params)