move pool_recycle and pool_pre_ping in config.py
This commit is contained in:
parent
f62e05fd06
commit
cd5845c180
@ -54,10 +54,14 @@ class StateStorageConfig:
|
|||||||
@dataclass
|
@dataclass
|
||||||
class DatabaseConfig:
|
class DatabaseConfig:
|
||||||
url: str
|
url: str
|
||||||
|
pool_recycle: int
|
||||||
|
pool_pre_ping: bool
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_env(cls):
|
def from_env(cls):
|
||||||
return cls(os.getenv("DATABASE_URL", "sqlite:///bot.db"))
|
return cls(os.getenv("DB_URL", "sqlite:///bot.db"),
|
||||||
|
int(os.getenv("DB_POOL_RECYCLE", 3600)),
|
||||||
|
bool(int(os.getenv("DB_POOL_PRE_PING", True))))
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@ -7,8 +7,8 @@ from .models import User
|
|||||||
|
|
||||||
def get_engine(config: DatabaseConfig):
|
def get_engine(config: DatabaseConfig):
|
||||||
engine = create_engine(config.url,
|
engine = create_engine(config.url,
|
||||||
pool_recycle=3600,
|
pool_recycle=config.pool_recycle,
|
||||||
pool_pre_ping=True)
|
pool_pre_ping=config.pool_pre_ping)
|
||||||
return engine
|
return engine
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user