Update endpoint health check and datetime handling

Added 302 status code as healthy for Sayobot endpoint in BeatmapDownloadService. Improved datetime parsing to use UTC-aware datetimes in EnhancedIntervalStatsManager and removed redundant comments for Redis history trimming.
This commit is contained in:
咕谷酱
2025-08-22 20:44:58 +08:00
parent 4566ecbab5
commit 1f40c6f70d
2 changed files with 5 additions and 6 deletions

View File

@@ -141,8 +141,8 @@ class BeatmapDownloadService:
# 根据不同端点类型判断健康状态
is_healthy = False
if endpoint.name == "Sayobot":
# Sayobot 端点返回 304 (Not Modified) 表示正常
is_healthy = response.status_code in [200, 304]
# Sayobot 端点返回 200, 302 (Redirect), 304 (Not Modified) 表示正常
is_healthy = response.status_code in [200, 302, 304]
else:
# 其他端点返回 200 表示正常
is_healthy = response.status_code == 200

View File

@@ -5,7 +5,7 @@
from __future__ import annotations
from dataclasses import dataclass
from datetime import datetime, timedelta
from datetime import datetime, timedelta, UTC
import json
from app.dependencies.database import get_redis, get_redis_message
@@ -387,9 +387,7 @@ class EnhancedIntervalStatsManager:
# 添加到历史记录
await _redis_exec(redis_sync.lpush, REDIS_ONLINE_HISTORY_KEY, json.dumps(history_point))
# 只保留48个数据点24小时每30分钟一个点
await _redis_exec(redis_sync.ltrim, REDIS_ONLINE_HISTORY_KEY, 0, 47)
# 设置过期时间为26小时确保有足够缓冲
await redis_async.expire(REDIS_ONLINE_HISTORY_KEY, 26 * 3600)
logger.info(
@@ -444,7 +442,8 @@ class EnhancedIntervalStatsManager:
else:
key_str = key
time_part = key_str.split(":")[-1] # YYYYMMDD_HHMM格式
key_time = datetime.strptime(time_part, "%Y%m%d_%H%M")
# 将时区无关的datetime转换为UTC时区感知的datetime进行比较
key_time = datetime.strptime(time_part, "%Y%m%d_%H%M").replace(tzinfo=UTC)
if key_time < cutoff_time:
await redis_async.delete(key)