-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsgi.py
35 lines (30 loc) · 1.15 KB
/
wsgi.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
from gevent import monkey
monkey.patch_all()
import os
import sys
import logging
from accoj.utils.log_util import RedirectStderr
from dotenv import load_dotenv
from accoj import create_app
from gevent.pywsgi import WSGIServer
# from accoj.news_spider import periodic_run_news_spider
# from accoj.update_rank import periodic_update_user_rank
if __name__ == '__main__':
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
if os.path.exists(dotenv_path):
load_dotenv(dotenv_path)
app = create_app('development')
# 静态文件热更
app.jinja_env.auto_reload = True
# 后台启动爬虫
# periodic_run_news_spider.delay()
# 后台启动排行榜更新
# periodic_update_user_rank.delay()
# 日志stderr重定向
if not app.config.get('DEBUG'):
sys.stderr = RedirectStderr({'log_path': app.config.get('LOG_PATH')})
logging.basicConfig(filename=app.config.get('LOG_DEBUG_PATH'), level=logging.DEBUG)
host = app.config['HOST']
port = app.config['PORT']
http_server = WSGIServer(listener=(host, port), application=app)
http_server.serve_forever()