feat: 增加详细日志记录并支持热重载、过载情况不计入错误阈值计数、请求日志显示详细信息

fix: 修改进度查询接口
refactor: 移除去水印功能中的公开视频处理逻辑

Close #38
This commit is contained in:
TheSmallHanCat
2025-12-23 13:01:32 +08:00
parent 9cd14b858e
commit 2f6fc345a9
7 changed files with 194 additions and 73 deletions

View File

@@ -404,13 +404,31 @@ class GenerationHandler:
if is_video and self.concurrency_manager:
await self.concurrency_manager.release_video(token_obj.id)
# Log successful request
# Log successful request with complete task info
duration = time.time() - start_time
# Get complete task info from database
task_info = await self.db.get_task(task_id)
response_data = {
"task_id": task_id,
"status": "success",
"prompt": prompt,
"model": model
}
# Add result_urls if available
if task_info and task_info.result_urls:
try:
result_urls = json.loads(task_info.result_urls)
response_data["result_urls"] = result_urls
except:
response_data["result_urls"] = task_info.result_urls
await self._log_request(
token_obj.id,
f"generate_{model_config['type']}",
{"model": model, "prompt": prompt, "has_image": image is not None},
{"task_id": task_id, "status": "success"},
response_data,
200,
duration
)
@@ -427,9 +445,11 @@ class GenerationHandler:
if is_video and token_obj and self.concurrency_manager:
await self.concurrency_manager.release_video(token_obj.id)
# Record error
# Record error (check if it's an overload error)
if token_obj:
await self.token_manager.record_error(token_obj.id)
error_str = str(e).lower()
is_overload = "heavy_load" in error_str or "under heavy load" in error_str
await self.token_manager.record_error(token_obj.id, is_overload=is_overload)
# Log failed request
duration = time.time() - start_time
@@ -1254,9 +1274,11 @@ class GenerationHandler:
await self.token_manager.record_success(token_obj.id, is_video=True)
except Exception as e:
# Record error
# Record error (check if it's an overload error)
if token_obj:
await self.token_manager.record_error(token_obj.id)
error_str = str(e).lower()
is_overload = "heavy_load" in error_str or "under heavy load" in error_str
await self.token_manager.record_error(token_obj.id, is_overload=is_overload)
debug_logger.log_error(
error_message=f"Character and video generation failed: {str(e)}",
status_code=500,
@@ -1341,9 +1363,11 @@ class GenerationHandler:
await self.token_manager.record_success(token_obj.id, is_video=True)
except Exception as e:
# Record error
# Record error (check if it's an overload error)
if token_obj:
await self.token_manager.record_error(token_obj.id)
error_str = str(e).lower()
is_overload = "heavy_load" in error_str or "under heavy load" in error_str
await self.token_manager.record_error(token_obj.id, is_overload=is_overload)
debug_logger.log_error(
error_message=f"Remix generation failed: {str(e)}",
status_code=500,

View File

@@ -291,7 +291,7 @@ class SoraClient:
Returns:
List of pending tasks with progress information
"""
result = await self._make_request("GET", "/nf/pending", token)
result = await self._make_request("GET", "/nf/pending/v2", token)
# The API returns a list directly
return result if isinstance(result, list) else []

View File

@@ -982,16 +982,22 @@ class TokenManager:
else:
await self.db.increment_image_count(token_id)
async def record_error(self, token_id: int):
"""Record token error"""
await self.db.increment_error_count(token_id)
async def record_error(self, token_id: int, is_overload: bool = False):
"""Record token error
# Check if should ban
stats = await self.db.get_token_stats(token_id)
admin_config = await self.db.get_admin_config()
Args:
token_id: Token ID
is_overload: Whether this is an overload error (heavy_load). If True, only increment total error count.
"""
await self.db.increment_error_count(token_id, increment_consecutive=not is_overload)
if stats and stats.consecutive_error_count >= admin_config.error_ban_threshold:
await self.db.update_token_status(token_id, False)
# Check if should ban (only if not overload error)
if not is_overload:
stats = await self.db.get_token_stats(token_id)
admin_config = await self.db.get_admin_config()
if stats and stats.consecutive_error_count >= admin_config.error_ban_threshold:
await self.db.update_token_status(token_id, False)
async def record_success(self, token_id: int, is_video: bool = False):
"""Record successful request (reset error count)"""