-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the celery configuration and tasks
- Loading branch information
Showing
13 changed files
with
407 additions
and
77 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
import asyncio | ||
|
||
from celery import Task | ||
from sqlalchemy.exc import SQLAlchemyError | ||
|
||
from backend.app.task.conf import task_settings | ||
from backend.common.socketio.actions import task_notification | ||
|
||
|
||
class TaskBase(Task): | ||
"""任务基类(已自动应用到 celery)""" | ||
|
||
autoretry_for = (SQLAlchemyError,) | ||
max_retries = task_settings.CELERY_TASK_MAX_RETRIES | ||
|
||
def before_start(self, task_id, args, kwargs): | ||
asyncio.run(task_notification(msg=f'任务 {task_id} 开始执行')) | ||
|
||
def on_success(self, retval, task_id, args, kwargs): | ||
asyncio.run(task_notification(msg=f'任务 {task_id} 执行成功')) | ||
|
||
def on_failure(self, exc, task_id, args, kwargs, einfo): | ||
asyncio.run(task_notification(msg=f'任务 {task_id} 执行失败')) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,19 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
from sqlalchemy.exc import SQLAlchemyError | ||
|
||
from backend.app.admin.service.login_log_service import login_log_service | ||
from backend.app.admin.service.opera_log_service import opera_log_service | ||
from backend.app.task.celery import celery_app | ||
from backend.app.task.conf import task_settings | ||
|
||
|
||
@celery_app.task( | ||
name='auto_delete_db_opera_log', | ||
bind=True, | ||
retry_backoff=True, | ||
max_retries=task_settings.CELERY_TASK_MAX_RETRIES, | ||
) | ||
async def auto_delete_db_opera_log(self) -> int: | ||
@celery_app.task(name='delete_db_opera_log') | ||
async def delete_db_opera_log() -> int: | ||
"""自动删除数据库操作日志""" | ||
try: | ||
result = await opera_log_service.delete_all() | ||
except SQLAlchemyError as exc: | ||
raise self.retry(exc=exc) | ||
result = await opera_log_service.delete_all() | ||
return result | ||
|
||
|
||
@celery_app.task( | ||
name='auto_delete_db_login_log', | ||
bind=True, | ||
retry_backoff=True, | ||
max_retries=task_settings.CELERY_TASK_MAX_RETRIES, | ||
) | ||
async def auto_delete_db_login_log(self) -> int: | ||
@celery_app.task(name='delete_db_login_log') | ||
async def delete_db_login_log() -> int: | ||
"""自动删除数据库登录日志""" | ||
|
||
try: | ||
result = await login_log_service.delete_all() | ||
except SQLAlchemyError as exc: | ||
raise self.retry(exc=exc) | ||
result = await login_log_service.delete_all() | ||
return result |
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
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
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
File renamed without changes.
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
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
Oops, something went wrong.