def init_redis(): global GRedis if GRedis is not None: LOG.warning("Do not call init_redis more then once") return with lock.get('redis'): if GRedis is None: if SERVER_ID is None: init_server_id() conf = CONF[manager_group.name] kwargs = dict( server_id=SERVER_ID, max_connections=conf.redis_pool_size, host=conf.redis_host, port=conf.redis_port, db=conf.redis_db, password=conf.redis_password, socket_connect_timeout=conf.redis_connect_timeout, socket_timeout=conf.redis_socket_timeout, heart_beat_over_time=conf.redis_heartbeat_overtime, heart_beat_over_time_max_count=conf. redis_heartbeat_overtime_max_count, ) redis_client = GRedisPool.from_url(**kwargs) redis_client.start() GRedis = redis_client
def init_rpc_client(): global RPCClient if RPCClient is None: with lock.get('rpc'): if RPCClient is None: LOG.info("Try init rpc client for manager") RPCClient = ManagerRpcClient() else: LOG.warning("Do not call init_rpc_client more then once")
def init_global(): global GlobalDataClient if GlobalDataClient is None: with lock.get('global'): if GlobalDataClient is None: LOG.info("Try init glock client for manager") GlobalDataClient = GlobalData(client=get_redis(), session=get_session) else: LOG.warning("Do not call init_global more then once")
def init_endpoint_session(): global DbDriver if DbDriver is None: with lock.get('mysql-gopdb'): if DbDriver is None: LOG.info("Try connect database for gopdb") mysql_driver = MysqlDriver(common.DB, CONF[common.DB]) mysql_driver.start() DbDriver = mysql_driver else: LOG.warning("Do not call init_endpoint_session more then once")
def init_mysql_session(): global DbDriver if DbDriver is None: with lock.get('mysql'): if DbDriver is None: LOG.info("Try connect database for manager, lazy load") mysql_driver = MysqlDriver(manager_group.name, CONF[manager_group.name]) mysql_driver.start() DbDriver = mysql_driver else: LOG.warning("Do not call init_mysql_session more then once")
def init_http_client(): global HTTPClient if HTTPClient is None: with lock.get('http'): if HTTPClient is None: LOG.debug("Try init http client for manager") conf = CONF[manager_group.name] HTTPClient = ManagerClient(url=conf.gcenter, port=conf.gcenter_port, token=conf.trusted) else: LOG.warning("Do not call init_http_client more then once")
def init_gamelock(): global GameLock if GameLock is None: with lock.get('gamelock-gogamechen1'): if GameLock is None: LOG.info("Try init gamelock for gogamechen1") from goperation.manager.api import get_global from gogamechen1.api import gamelock gogamechen1_lock = gamelock.GoGameLock(gdata=get_global()) GameLock = gogamechen1_lock else: LOG.warning("Do not call init_gamelock more then once")
def init_server_id(): global SERVER_ID if SERVER_ID is None: with lock.get('sid'): if SERVER_ID is None: session = get_session() with session.begin(subtransactions=True): query = model_query(session, GkeyMap, filter=GkeyMap.host == CONF.host) result = query.one_or_none() if not result: upquery = model_query(session, GkeyMap, filter=GkeyMap.host == None) upquery.update(dict(host=CONF.host), update_args={'mysql_limit': 1}) result = query.one() SERVER_ID = result.sid else: LOG.warning("Do not call init_server_id more then once")