-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
48 lines (36 loc) · 1.21 KB
/
main.py
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
from configure import configure, conf
import os
import logging
import threading
env_dict = os.environ
hblog_conf = env_dict.get("HBLOG_CONF")
if hblog_conf is None:
logging.info("Configure file ./etc/conf.json")
configure("./etc/conf.json")
else:
logging.info(f"Configure file {hblog_conf}")
configure(hblog_conf)
from app import HBlogFlask
from waitress import serve
app = HBlogFlask(__name__)
app.register_all_blueprint()
from sql.cache import restart_clear_cache
from sql.cache_refresh import refresh
restart_clear_cache() # 清理缓存
@app.before_first_request
def before_first_requests():
class FirstRefresh(threading.Thread):
def __init__(self):
super(FirstRefresh, self).__init__()
self.daemon = True # 设置为守护进程
def run(self):
refresh()
class TimerRefresh(threading.Timer):
def __init__(self):
super(TimerRefresh, self).__init__(conf["CACHE_REFRESH_INTERVAL"], refresh)
self.daemon = True # 设置为守护进程
FirstRefresh().start()
TimerRefresh().start()
if __name__ == '__main__':
logging.info("Server start on 127.0.0.1:8080")
serve(app, host='0.0.0.0', port="8080")