forked from damnever/wechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
57 lines (43 loc) · 1.61 KB
/
app.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
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tornado.web
import tornado.httpserver
import tornado.ioloop
from tornado.options import define, options
from libs.message import MessageProducter
from libs.utils import parse_configure_file, join_path
from models import mysql, rds
from taskq.connection import Connection
define('port', default=8888, help='run on the given port', type=int)
class Application(tornado.web.Application):
def __init__(self):
from handlers import urls
from libs.handler import DefaultHandler
db = mysql.connect(
options.db_host, options.db_database,
options.db_user, options.db_passwd
)
settings = {
'static_path': join_path(__file__, 'static'),
'template_path': join_path(__file__, 'templates'),
'cookie_secret': options.cookie_secret,
'xsrf_cookies': options.xsrf_cookies,
'login_url': options.login_url,
'debug': options.debug,
'default_handler_class': DefaultHandler,
'db': db,
'rds': rds.Rds(),
'msg_producer': MessageProducter(),
}
tornado.web.Application.__init__(self, urls, **settings)
def run_server():
# For task queue
Connection.setup(db=3)
parse_configure_file(options, define, join_path(__file__, './chat.conf'))
options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(
Application(), xheaders=options.xheaders)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == '__main__':
run_server()