|
|
|
@ -10,12 +10,12 @@ import tornado.ioloop
|
|
|
|
|
import tornado.options
|
|
|
|
|
import tornado.web
|
|
|
|
|
# import tornado.websocket
|
|
|
|
|
import torndb
|
|
|
|
|
# import torndb
|
|
|
|
|
import importlib
|
|
|
|
|
# from confluent_kafka import Producer
|
|
|
|
|
# from rediscluster import StrictRedisCluster
|
|
|
|
|
# from redis import sentinel
|
|
|
|
|
from rediscluster import RedisCluster
|
|
|
|
|
# from rediscluster import RedisCluster
|
|
|
|
|
# from redis.sentinel import Sentinel
|
|
|
|
|
# from tornado.options import define, options
|
|
|
|
|
from tornado.options import options, define as _define, parse_command_line
|
|
|
|
@ -59,54 +59,54 @@ from website.urls import handlers, page_handlers
|
|
|
|
|
# from website.urls import handlers_v2
|
|
|
|
|
# print(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
|
|
|
|
class Connection(torndb.Connection):
|
|
|
|
|
def __init__(self,
|
|
|
|
|
host,
|
|
|
|
|
database,
|
|
|
|
|
user=None,
|
|
|
|
|
password=None,
|
|
|
|
|
max_idle_time=7 * 3600,
|
|
|
|
|
connect_timeout=500,
|
|
|
|
|
time_zone="+0:00"):
|
|
|
|
|
self.host = host
|
|
|
|
|
self.database = database
|
|
|
|
|
self.max_idle_time = float(max_idle_time)
|
|
|
|
|
|
|
|
|
|
args = dict(conv=torndb.CONVERSIONS,
|
|
|
|
|
use_unicode=True,
|
|
|
|
|
charset="utf8",
|
|
|
|
|
db=database,
|
|
|
|
|
init_command=('SET time_zone = "%s";' %
|
|
|
|
|
time_zone),
|
|
|
|
|
connect_timeout=connect_timeout,
|
|
|
|
|
sql_mode="TRADITIONAL")
|
|
|
|
|
if user is not None:
|
|
|
|
|
args["user"] = user
|
|
|
|
|
if password is not None:
|
|
|
|
|
args["passwd"] = password
|
|
|
|
|
|
|
|
|
|
# We accept a path to a MySQL socket file or a host(:port) string
|
|
|
|
|
if "/" in host:
|
|
|
|
|
args["unix_socket"] = host
|
|
|
|
|
else:
|
|
|
|
|
self.socket = None
|
|
|
|
|
pair = host.split(":")
|
|
|
|
|
if len(pair) == 2:
|
|
|
|
|
args["host"] = pair[0]
|
|
|
|
|
args["port"] = int(pair[1])
|
|
|
|
|
else:
|
|
|
|
|
args["host"] = host
|
|
|
|
|
args["port"] = 3306
|
|
|
|
|
|
|
|
|
|
self._db = None
|
|
|
|
|
self._db_args = args
|
|
|
|
|
self._last_use_time = time.time()
|
|
|
|
|
try:
|
|
|
|
|
self.reconnect()
|
|
|
|
|
except Exception:
|
|
|
|
|
logging.error("Cannot connect to MySQL on %s",
|
|
|
|
|
self.host,
|
|
|
|
|
exc_info=True)
|
|
|
|
|
# class Connection(torndb.Connection):
|
|
|
|
|
# def __init__(self,
|
|
|
|
|
# host,
|
|
|
|
|
# database,
|
|
|
|
|
# user=None,
|
|
|
|
|
# password=None,
|
|
|
|
|
# max_idle_time=7 * 3600,
|
|
|
|
|
# connect_timeout=500,
|
|
|
|
|
# time_zone="+0:00"):
|
|
|
|
|
# self.host = host
|
|
|
|
|
# self.database = database
|
|
|
|
|
# self.max_idle_time = float(max_idle_time)
|
|
|
|
|
#
|
|
|
|
|
# args = dict(conv=torndb.CONVERSIONS,
|
|
|
|
|
# use_unicode=True,
|
|
|
|
|
# charset="utf8",
|
|
|
|
|
# db=database,
|
|
|
|
|
# init_command=('SET time_zone = "%s";' %
|
|
|
|
|
# time_zone),
|
|
|
|
|
# connect_timeout=connect_timeout,
|
|
|
|
|
# sql_mode="TRADITIONAL")
|
|
|
|
|
# if user is not None:
|
|
|
|
|
# args["user"] = user
|
|
|
|
|
# if password is not None:
|
|
|
|
|
# args["passwd"] = password
|
|
|
|
|
#
|
|
|
|
|
# # We accept a path to a MySQL socket file or a host(:port) string
|
|
|
|
|
# if "/" in host:
|
|
|
|
|
# args["unix_socket"] = host
|
|
|
|
|
# else:
|
|
|
|
|
# self.socket = None
|
|
|
|
|
# pair = host.split(":")
|
|
|
|
|
# if len(pair) == 2:
|
|
|
|
|
# args["host"] = pair[0]
|
|
|
|
|
# args["port"] = int(pair[1])
|
|
|
|
|
# else:
|
|
|
|
|
# args["host"] = host
|
|
|
|
|
# args["port"] = 3306
|
|
|
|
|
#
|
|
|
|
|
# self._db = None
|
|
|
|
|
# self._db_args = args
|
|
|
|
|
# self._last_use_time = time.time()
|
|
|
|
|
# try:
|
|
|
|
|
# self.reconnect()
|
|
|
|
|
# except Exception:
|
|
|
|
|
# logging.error("Cannot connect to MySQL on %s",
|
|
|
|
|
# self.host,
|
|
|
|
|
# exc_info=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# class NoCacheStaticFileHandler(tornado.web.StaticFileHandler):
|
|
|
|
@ -158,11 +158,12 @@ class Application(tornado.web.Application):
|
|
|
|
|
# self.r_app = rs.master_for(settings.redis_sentinel_master,
|
|
|
|
|
# socket_timeout=0.1,
|
|
|
|
|
# password=settings.redis_sentinel_pwd)
|
|
|
|
|
if settings.redis_cluster == 1:
|
|
|
|
|
self.r_app = RedisCluster(startup_nodes=settings.redis_app_cluster_notes, decode_responses=True,
|
|
|
|
|
password=settings.redis_cluster_pwd)
|
|
|
|
|
else:
|
|
|
|
|
self.r_app = redis.Redis(*settings.redis_app, decode_responses=True)
|
|
|
|
|
# if settings.redis_cluster == 1:
|
|
|
|
|
# self.r_app = RedisCluster(startup_nodes=settings.redis_app_cluster_notes, decode_responses=True,
|
|
|
|
|
# password=settings.redis_cluster_pwd)
|
|
|
|
|
# else:
|
|
|
|
|
# self.r_app = redis.Redis(*settings.redis_app, decode_responses=True)
|
|
|
|
|
self.r_app = redis.Redis(*settings.redis_app, decode_responses=True)
|
|
|
|
|
# self.r_app = redis.Redis(*settings.redis_app)
|
|
|
|
|
|
|
|
|
|
# self.kafka_producer = Producer(**settings.kafka_conf)
|
|
|
|
|