This commit is contained in:
wuhao 2020-11-13 20:19:35 +08:00
parent ab3b196cba
commit 1a0048ec15

View File

@ -1,4 +1,5 @@
import hashlib import hashlib
import os
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
import traceback import traceback
import arrow import arrow
@ -13,14 +14,14 @@ class Handler(metaclass=ABCMeta):
def __init__(self, data): def __init__(self, data):
self._data = data self._data = data
self._appid = data['appid'] appid = data['appid']
self._event = self._data['event'] self._event = self._data['event']
self._game = self._data['project'] self._game = self._data['project']
self._type = self._data['type'] self._type = self._data['type']
Handler._init_game_config(self._appid) Handler._init_game_config()
Handler._init_mdb(f'{settings.DB_PREFIX}_{Handler.game_config["id_name"]}') Handler._init_mdb(f'{settings.DB_PREFIX}_{Handler.game_config[appid]["id_name"]}')
self.secret_token = Handler.game_config.get('secret_token', '') self.secret_token = Handler.game_config[appid].get('secret_token', '')
self._nt = arrow.now(tz=Handler.game_config.get('timezone', 'local')).timestamp self._nt = arrow.now(tz=Handler.game_config[appid].get('timezone', 'local')).timestamp
@classmethod @classmethod
def _init_mdb(cls, dbname): def _init_mdb(cls, dbname):
@ -44,9 +45,11 @@ class Handler(metaclass=ABCMeta):
coll.update_one(where, {'$set': update_data}, upsert=True) coll.update_one(where, {'$set': update_data}, upsert=True)
@classmethod @classmethod
def _init_game_config(cls, appid): def _init_game_config(cls):
if not cls.game_config: if not cls.game_config:
cls.game_config = settings.admin_game_coll.find_one({'appid': appid}) topic_list = settings.kafka_setting['topic_name']
data = settings.admin_game_coll.find({'appid': {'$in': topic_list}}, {'_id': False})
cls.game_config = {item['appid']:item for item in data}
return cls.game_config return cls.game_config
def handler_event(self): def handler_event(self):