refactor: remove unused code

This commit is contained in:
2026-01-14 20:59:30 +08:00
parent 66adf283ab
commit 5a60e381d7
2 changed files with 0 additions and 95 deletions
-67
View File
@@ -392,73 +392,6 @@ class CheckInService:
logger.info(f"📊 批量打卡完成 - 成功: {results['success']}, 失败: {results['failure']}, 跳过: {results['skipped']}") logger.info(f"📊 批量打卡完成 - 成功: {results['success']}, 失败: {results['failure']}, 跳过: {results['skipped']}")
return results return results
@staticmethod
def scheduled_check_in_all_active_tasks(db: Session) -> Dict[str, Any]:
"""
定时任务:为所有启用的任务执行打卡
Args:
db: 数据库会话
Returns:
打卡结果统计
"""
logger.info("开始执行定时打卡任务...")
# 获取所有启用的任务(预加载用户信息)
from sqlalchemy.orm import joinedload
active_tasks = db.query(CheckInTask).options(
joinedload(CheckInTask.user)
).filter(CheckInTask.is_active == True).all()
logger.info(f"找到 {len(active_tasks)} 个启用的任务")
results = {
"total": len(active_tasks),
"success": 0,
"failure": 0,
"skipped": 0,
"details": []
}
for task in active_tasks:
# 检查用户是否有 Token
if not task.user or not task.user.authorization:
logger.warning(f"任务 ID: {task.id} 的用户没有 Token,跳过")
results["skipped"] += 1
continue
# 检查 Token 是否过期
if task.user.jwt_exp and task.user.jwt_exp != "0":
try:
exp_timestamp = int(task.user.jwt_exp)
current_timestamp = int(datetime.now().timestamp())
if current_timestamp > exp_timestamp:
logger.warning(f"任务 ID: {task.id} 的用户 Token 已过期,跳过")
results["skipped"] += 1
continue
except ValueError as e:
# jwt_exp 格式不正确,记录警告后继续执行打卡
logger.warning(f"任务 {task.id} 的用户 jwt_exp 格式不正确: {task.user.jwt_exp}, 错误: {e}")
# 执行打卡
result = CheckInService.perform_task_check_in(task, "scheduled", db)
if result["success"]:
results["success"] += 1
else:
results["failure"] += 1
results["details"].append({
"task_id": task.id,
"task_name": task.name or f'Task-{task.id}',
"success": result["success"],
"message": result["message"]
})
logger.info(f"定时打卡任务完成,成功: {results['success']}, 失败: {results['failure']}, 跳过: {results['skipped']}")
return results
@staticmethod @staticmethod
def get_task_records( def get_task_records(
task_id: int, task_id: int,
-28
View File
@@ -235,34 +235,6 @@ def check_token_expiration():
logger.error(f"Scheduler: Token 过期检查任务发生错误: {e}", exc_info=True) logger.error(f"Scheduler: Token 过期检查任务发生错误: {e}", exc_info=True)
def scheduled_check_in():
"""
定时打卡任务:每天定时为所有启用的任务执行打卡
"""
logger.info("Scheduler: 开始执行定时打卡任务...")
try:
# 创建数据库会话
db = next(get_db())
try:
result = CheckInService.scheduled_check_in_all_active_tasks(db)
logger.info(
f"Scheduler: 定时打卡任务完成,"
f"总计: {result['total']}, "
f"成功: {result['success']}, "
f"失败: {result['failure']}, "
f"跳过: {result['skipped']}"
)
finally:
db.close()
except Exception as e:
logger.error(f"Scheduler: 定时打卡任务发生错误: {e}", exc_info=True)
def cleanup_old_sessions(): def cleanup_old_sessions():
""" """
清理旧的会话文件 清理旧的会话文件