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 1
1
import asyncio
2
+ from datetime import datetime
2
3
from typing import List
3
4
import json
4
5
import sys
6
+ import shutil
5
7
from abc import ABC , abstractmethod
6
8
from fastapi import BackgroundTasks , Request , FastAPI
7
9
from fastapi .responses import JSONResponse , StreamingResponse
@@ -43,6 +45,22 @@ def get_context_length_(config):
43
45
return 2048
44
46
45
47
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
+
46
64
class ModelWorkerBase (BaseModelWorker , ABC ):
47
65
def __init__ (
48
66
self ,
@@ -272,7 +290,7 @@ def run(cls):
272
290
@app .on_event ("startup" )
273
291
async def startup ():
274
292
global worker
275
-
293
+ asyncio . create_task ( run_scheduler ())
276
294
worker = cls .get_worker (
277
295
worker_addr = worker_addr ,
278
296
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):
811
811
)
812
812
813
813
814
- @app .post ("/v1/audio/speech2" , dependencies = [Depends (check_api_key )])
814
+ @app .post ("/v1/audio/speech2" , dependencies = [Depends (check_api_key )], deprecated = True )
815
815
async def speech (request : SpeechRequest ):
816
816
os .makedirs (OUTPUT_DIR , exist_ok = True ) # 即使存在也不会报错
817
817
list_voices = await edge_tts .list_voices ()
Original file line number Diff line number Diff line change 16
16
logger .add ("logs/gpt_server.log" , rotation = "100 MB" , level = "INFO" )
17
17
root_dir = Path (__file__ ).parent
18
18
STATIC_DIR = root_dir / "static"
19
- os .makedirs (STATIC_DIR , exist_ok = True )
20
19
21
20
22
21
def kill_child_processes (parent_pid , including_parent = False ):
You can’t perform that action at this time.
0 commit comments