fix bug 6

This commit is contained in:
BryantHe 2023-05-30 20:22:54 +08:00
parent b7a6115ce9
commit b1773a4b81
2 changed files with 9 additions and 7 deletions

View File

@ -16,10 +16,12 @@ class Config:
# 指定数据库 # 指定数据库
DEFAULT_DATABASE_URI = os.getenv('DEFAULT_DATABASE_URI') DEFAULT_DATABASE_URI = os.getenv('DEFAULT_DATABASE_URI')
READONLY_DATABASE_URI = os.getenv('READONLY_DATABASE_URI') READONLY_DATABASE_URI = os.getenv('READONLY_DATABASE_URI')
const.DB_CONFIG_ITEM = { DB_CONFIG_ITEM = {
const.DB_CONFIG_ITEM: {
const.DEFAULT_DB_KEY: DEFAULT_DATABASE_URI, const.DEFAULT_DB_KEY: DEFAULT_DATABASE_URI,
const.READONLY_DB_KEY: READONLY_DATABASE_URI, const.READONLY_DB_KEY: READONLY_DATABASE_URI,
} }
}
STATSD_PREFIX = os.getenv('STATSD_PREFIX') STATSD_PREFIX = os.getenv('STATSD_PREFIX')
STATSD_HOST = os.getenv('STATSD_HOST') STATSD_HOST = os.getenv('STATSD_HOST')

View File

@ -7,11 +7,11 @@ from chassis.consts import const
engines = {} engines = {}
def init_engine(config): def init_engine(config_item):
if config: if config_item:
databases = getattr(config, const.DB_CONFIG_ITEM) databases = config_item[const.DB_CONFIG_ITEM]
else: else:
databases = getattr(Config, const.DB_CONFIG_ITEM) databases = Config.DB_CONFIG_ITEM[const.DB_CONFIG_ITEM]
for db_key, db_url in databases.items(): for db_key, db_url in databases.items():
engine = create_engine(db_url, engine = create_engine(db_url,
logging_name=db_key, poolclass=None, pool_size=5, max_overflow=20, pool_recycle=3600, logging_name=db_key, poolclass=None, pool_size=5, max_overflow=20, pool_recycle=3600,