添加日志
This commit is contained in:
parent
e6291fe3a4
commit
0c8c6ffbc2
3
.gitignore
vendored
3
.gitignore
vendored
@ -24,3 +24,6 @@ cache/
|
||||
*.so
|
||||
*.dll
|
||||
*.pyd
|
||||
|
||||
# log
|
||||
log/
|
||||
|
||||
@ -17,14 +17,24 @@ from . import mounter
|
||||
from . import queue_operation
|
||||
from . import scheduler
|
||||
import logging
|
||||
import os
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
)
|
||||
logger = logging.getLogger(__name__).addHandler(logging.NullHandler())
|
||||
# 设置 error 级别日志写入 error.log 文件
|
||||
if not os.path.exists("log"):
|
||||
os.mkdir("log")
|
||||
error_log_handler = logging.FileHandler("log/error.log", encoding="utf-8")
|
||||
error_log_handler.setLevel(logging.ERROR)
|
||||
error_log_handler.setFormatter(
|
||||
logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
)
|
||||
logging.getLogger().addHandler(error_log_handler)
|
||||
# logger = logging.getLogger(__name__).addHandler(logging.NullHandler())
|
||||
|
||||
__title__ = "queue_sqlite"
|
||||
__version__ = "0.1.0"
|
||||
__version__ = "0.2.0"
|
||||
__author__ = "chakcy"
|
||||
__email__ = "947105045@qq.com"
|
||||
__license__ = "MIT"
|
||||
|
||||
@ -33,6 +33,12 @@ class TaskMounter:
|
||||
def get_task_function(cls, name: str):
|
||||
return getattr(cls, name, None)
|
||||
|
||||
@classmethod
|
||||
def get_task_meta(cls, task_name: str):
|
||||
task_function = cls.get_task_function(task_name)
|
||||
if task_function:
|
||||
return getattr(task_function, "meta", {})
|
||||
|
||||
@classmethod
|
||||
def get_task_list(cls) -> List[str]:
|
||||
"""获取所有挂载的任务函数名称列表"""
|
||||
|
||||
@ -19,6 +19,7 @@ from datetime import datetime
|
||||
import threading
|
||||
import multiprocessing
|
||||
import logging
|
||||
import json
|
||||
|
||||
|
||||
class AsyncTaskScheduler:
|
||||
@ -67,7 +68,7 @@ class AsyncTaskScheduler:
|
||||
def _process_messages(self, message):
|
||||
"""更新任务结果到数据库"""
|
||||
try:
|
||||
self.queue_operation.update_result(message.id, message.result)
|
||||
self.queue_operation.update_result(message.id, json.dumps(message.result))
|
||||
self.queue_operation.update_status(message.id, message.status)
|
||||
except Exception as e:
|
||||
logging.error(f"任务结果更新失败: {str(e)}")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user