This repository was archived by the owner on Jan 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathapp_server.py
More file actions
45 lines (37 loc) · 1.47 KB
/
app_server.py
File metadata and controls
45 lines (37 loc) · 1.47 KB
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
#!/usr/bin/env python3
# coding=utf8
"""
Author: 归根落叶
Blog: https://www.bstester.com
"""
from tornado import httpserver, ioloop
from tornado.options import options, define
from tornado.web import Application
from includes.scheduler import job_monitor
from config import urls
from config import app as app_cfg
from config.db import init_db
class AppServer(Application):
"""应用启动入口"""
def __init__(self):
handlers = urls.handlers
settings = {'template_path': app_cfg.template_path,
'static_path': app_cfg.static_path,
'cookie_secret': app_cfg.cookie_secret,
'xsrf_cookie': app_cfg.xsrf_cookie,
'login_url': app_cfg.login_url,
'ui_modules': app_cfg.ui_modules,
'debug': app_cfg.debug}
Application.__init__(self, handlers, **settings)
def main():
define('port', default=app_cfg.app_port, help='run on the given port', type=int)
define('monitor', default='off', help='open jobs monitor', type=str)
options.parse_command_line()
http_server = httpserver.HTTPServer(AppServer(), xheaders=True)
http_server.listen(options.port)
if options.monitor.lower() == 'on':
ioloop.PeriodicCallback(job_monitor, app_cfg.cycle_time * 1000).start()
ioloop.IOLoop.instance().run_sync(init_db)
ioloop.IOLoop.instance().start()
if __name__ == '__main__':
main()