File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed
Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 11import asyncio
2+ from datetime import datetime
23from typing import List
34import json
45import sys
6+ import shutil
57from abc import ABC , abstractmethod
68from fastapi import BackgroundTasks , Request , FastAPI
79from fastapi .responses import JSONResponse , StreamingResponse
@@ -43,6 +45,22 @@ def get_context_length_(config):
4345 return 2048
4446
4547
48+ async def cleanup_static_files ():
49+ """清理静态文件目录并重建"""
50+ logger .info (f"{ datetime .now ()} 开始清理静态文件目录:{ STATIC_DIR } " )
51+ shutil .rmtree (STATIC_DIR , ignore_errors = True )
52+ os .makedirs (STATIC_DIR , exist_ok = True )
53+ logger .info (f"{ datetime .now ()} 清理完成" )
54+ await asyncio .sleep (1 ) # 60分钟 = 3600秒
55+
56+
57+ async def run_scheduler ():
58+ """每60分钟执行一定时任务"""
59+ while True :
60+ await cleanup_static_files ()
61+ await asyncio .sleep (60 * 60 ) # 60分钟 = 3600秒
62+
63+
4664class ModelWorkerBase (BaseModelWorker , ABC ):
4765 def __init__ (
4866 self ,
@@ -272,7 +290,7 @@ def run(cls):
272290 @app .on_event ("startup" )
273291 async def startup ():
274292 global worker
275-
293+ asyncio . create_task ( run_scheduler ())
276294 worker = cls .get_worker (
277295 worker_addr = worker_addr ,
278296 model_path = args .model_name_or_path ,
Original file line number Diff line number Diff line change @@ -811,7 +811,7 @@ async def speech(request: OpenAISpeechRequest):
811811 )
812812
813813
814- @app .post ("/v1/audio/speech2" , dependencies = [Depends (check_api_key )])
814+ @app .post ("/v1/audio/speech2" , dependencies = [Depends (check_api_key )], deprecated = True )
815815async def speech (request : SpeechRequest ):
816816 os .makedirs (OUTPUT_DIR , exist_ok = True ) # 即使存在也不会报错
817817 list_voices = await edge_tts .list_voices ()
Original file line number Diff line number Diff line change 1616logger .add ("logs/gpt_server.log" , rotation = "100 MB" , level = "INFO" )
1717root_dir = Path (__file__ ).parent
1818STATIC_DIR = root_dir / "static"
19- os .makedirs (STATIC_DIR , exist_ok = True )
2019
2120
2221def kill_child_processes (parent_pid , including_parent = False ):
You can’t perform that action at this time.
0 commit comments