File size: 1,734 Bytes
b9d0462
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

import uvicorn
from fastapi import FastAPI
from utils import *
from typing import *
from config import *
from apscheduler.schedulers.background import BackgroundScheduler#定时任务

scheduler = BackgroundScheduler()#这个不要用缓存的


def load_config():
    return get_variables()

class configData():
    def update(self):
        self.data = load_config()
        print(self.data)
        return self.data


configData = configData()#复用实例
app = FastAPI()

def periodic_function():
    data = configData.update()
    print(f'定时执行的操作时间:{datetime.now()}')
    print("是否允许定时任务",data['allow_scheduler'])
    run_asp_task()#执行asp任务进行发送




#启动app时候的定时任务 - 每天根据manga_abs_dir路径是否有jpg文件来判断是否运行
@app.on_event("startup")
async def app_start():
    #scheduler.add_job(periodic_function, 'interval', seconds=55)
    scheduler.add_job(periodic_function, 'interval', seconds=18000)#间隔5小时执行一次
    scheduler.start()



# 返回当前目录及其子目录下的所有信息
@app.get("/listFiles")
def list_files_func():
    result = list_files()
    return result

# 返回一个章节并删除
@app.get("/random_chapter")
def random_chapter_handler():
    result = random_chapter()
    return result




#两个blocks放到不同的地方,一个管理manga素材上传,一个管理任务处理
app = gr.mount_gradio_app(app, mangaManager, path="/gr")
#下面这个暂不更新->没想到太大作用
app = gr.mount_gradio_app(app, taskManager, path="/taskManager")

if __name__ == '__main__':

    uvicorn.run(app, host='0.0.0.0', port=7860)