server/migrations: implement database connection timeout
This commit is contained in:
parent
e3401b3993
commit
a616cf6987
1 changed files with 11 additions and 1 deletions
|
@ -4,6 +4,7 @@ import sys
|
||||||
import alembic
|
import alembic
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
import logging.config
|
import logging.config
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
# make szurubooru module importable
|
# make szurubooru module importable
|
||||||
dir_to_self = os.path.dirname(os.path.realpath(__file__))
|
dir_to_self = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
@ -56,7 +57,16 @@ def run_migrations_online():
|
||||||
prefix='sqlalchemy.',
|
prefix='sqlalchemy.',
|
||||||
poolclass=sa.pool.NullPool)
|
poolclass=sa.pool.NullPool)
|
||||||
|
|
||||||
with connectable.connect() as connection:
|
def connect_with_timeout(connectable, timeout=45):
|
||||||
|
dt = 5
|
||||||
|
for _ in range(int(timeout / dt)):
|
||||||
|
try:
|
||||||
|
return connectable.connect()
|
||||||
|
except sa.exc.OperationalError:
|
||||||
|
sleep(dt)
|
||||||
|
return connectable.connect()
|
||||||
|
|
||||||
|
with connect_with_timeout(connectable) as connection:
|
||||||
alembic.context.configure(
|
alembic.context.configure(
|
||||||
connection=connection,
|
connection=connection,
|
||||||
target_metadata=target_metadata,
|
target_metadata=target_metadata,
|
||||||
|
|
Loading…
Reference in a new issue