Skip to content

Commit db81319

Browse files
authored
Fix the failure hook of celery task (#569)
1 parent 644f7a0 commit db81319

File tree

1 file changed

+5
-2
lines changed
  • backend/app/task/celery_task

1 file changed

+5
-2
lines changed

backend/app/task/celery_task/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
3+
import asyncio
4+
35
from typing import Any
46

57
from celery import Task
@@ -34,7 +36,7 @@ async def on_success(self, retval: Any, task_id: str, args, kwargs) -> None:
3436
"""
3537
await task_notification(msg=f'任务 {task_id} 执行成功')
3638

37-
async def on_failure(self, exc: Exception, task_id: str, args, kwargs, einfo) -> None:
39+
def on_failure(self, exc: Exception, task_id: str, args, kwargs, einfo) -> None:
3840
"""
3941
任务失败后执行钩子
4042
@@ -43,4 +45,5 @@ async def on_failure(self, exc: Exception, task_id: str, args, kwargs, einfo) ->
4345
:param einfo: 异常信息
4446
:return:
4547
"""
46-
await task_notification(msg=f'任务 {task_id} 执行失败')
48+
loop = asyncio.get_event_loop()
49+
loop.create_task(task_notification(msg=f'任务 {task_id} 执行失败'))

0 commit comments

Comments
 (0)