task: add real estate story
All checks were successful
Gitea Actions Demo / deploy (push) Successful in 26s
All checks were successful
Gitea Actions Demo / deploy (push) Successful in 26s
This commit is contained in:
@ -7,7 +7,7 @@ from apscheduler.schedulers.blocking import BlockingScheduler
|
||||
from config import config
|
||||
from database.database import get_session
|
||||
from database.tscheduler.crud import get_tasks_by_executor
|
||||
from log.log_manager import log
|
||||
from utils import logger
|
||||
|
||||
"""
|
||||
这是一个特殊的任务,负责管理任务,命名为管理者任务。
|
||||
@ -26,10 +26,10 @@ def log_task_execution(task_name: str, start_time: float, end_time: float = None
|
||||
start_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(start_time))
|
||||
end_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(end_time))
|
||||
if end_time is None:
|
||||
log(f"{task_name} start execute at {start_time_str}")
|
||||
logger.info(f"{task_name} start execute at {start_time_str}")
|
||||
else:
|
||||
elapsed_time = end_time - start_time
|
||||
log(f"{task_name} end execute at {end_time_str}, use time {elapsed_time:.2f} seconds")
|
||||
logger.info(f"{task_name} end execute at {end_time_str}, use time {elapsed_time:.2f} seconds")
|
||||
|
||||
|
||||
def execute_task(task: callable):
|
||||
@ -65,7 +65,7 @@ def load_tasks(scheduler: BlockingScheduler):
|
||||
id=str(task_id),
|
||||
replace_existing=True
|
||||
)
|
||||
log(f"Task {task.task_name} added with interval {interval_seconds} seconds")
|
||||
logger.info(f"Task {task.task_name} added with interval {interval_seconds} seconds")
|
||||
elif trigger == "cron":
|
||||
# 解析 cron 表达式的字段
|
||||
fields = task.cron_expression.split()
|
||||
@ -89,7 +89,7 @@ def load_tasks(scheduler: BlockingScheduler):
|
||||
id=str(task_id),
|
||||
replace_existing=True
|
||||
)
|
||||
log(f"Task {task.task_name} added with cron {task.cron_expression}")
|
||||
logger.info(f"Task {task.task_name} added with cron {task.cron_expression}")
|
||||
elif trigger == "date":
|
||||
scheduler.add_job(
|
||||
task_function,
|
||||
@ -98,9 +98,9 @@ def load_tasks(scheduler: BlockingScheduler):
|
||||
id=str(task_id),
|
||||
replace_existing=True
|
||||
)
|
||||
log(f"Task {task.task_name} added with date {task.execution_date}")
|
||||
logger.info(f"Task {task.task_name} added with date {task.execution_date}")
|
||||
else:
|
||||
log(f"Invalid trigger type: {trigger}")
|
||||
logger.warning(f"Invalid trigger type: {trigger}")
|
||||
|
||||
|
||||
# 管理者任务
|
||||
|
||||
Reference in New Issue
Block a user