mirror of
https://github.com/Mailu/Mailu.git
synced 2025-04-17 11:56:22 +02:00
update tenacity
This commit is contained in:
parent
833ccb5544
commit
f613205fe1
@ -1,10 +1,12 @@
|
||||
from __future__ import with_statement
|
||||
import logging
|
||||
import tenacity
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
from logging.config import fileConfig
|
||||
import logging
|
||||
import tenacity
|
||||
from tenacity import retry
|
||||
|
||||
from flask import current_app
|
||||
from mailu import models
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
@ -17,20 +19,12 @@ logger = logging.getLogger('alembic.env')
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
from flask import current_app
|
||||
config.set_main_option('sqlalchemy.url',
|
||||
current_app.config.get('SQLALCHEMY_DATABASE_URI'))
|
||||
#target_metadata = current_app.extensions['migrate'].db.metadata
|
||||
from mailu import models
|
||||
config.set_main_option(
|
||||
'sqlalchemy.url',
|
||||
current_app.config.get('SQLALCHEMY_DATABASE_URI')
|
||||
)
|
||||
target_metadata = models.Base.metadata
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
# my_important_option = config.get_main_option("my_important_option")
|
||||
# ... etc.
|
||||
|
||||
|
||||
def run_migrations_offline():
|
||||
"""Run migrations in 'offline' mode.
|
||||
@ -44,7 +38,7 @@ def run_migrations_offline():
|
||||
script output.
|
||||
|
||||
"""
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
url = config.get_main_option('sqlalchemy.url')
|
||||
context.configure(url=url)
|
||||
|
||||
with context.begin_transaction():
|
||||
@ -69,27 +63,34 @@ def run_migrations_online():
|
||||
directives[:] = []
|
||||
logger.info('No changes in schema detected.')
|
||||
|
||||
engine = engine_from_config(config.get_section(config.config_ini_section),
|
||||
engine = engine_from_config(
|
||||
config.get_section(config.config_ini_section),
|
||||
prefix = 'sqlalchemy.',
|
||||
poolclass=pool.NullPool)
|
||||
poolclass = pool.NullPool
|
||||
)
|
||||
|
||||
connection = tenacity.Retrying(
|
||||
@tenacity.retry(
|
||||
stop = tenacity.stop_after_attempt(100),
|
||||
wait = tenacity.wait_random(min=2, max=5),
|
||||
before=tenacity.before_log(logging.getLogger("tenacity.retry"), logging.DEBUG),
|
||||
before_sleep=tenacity.before_sleep_log(logging.getLogger("tenacity.retry"), logging.INFO),
|
||||
after=tenacity.after_log(logging.getLogger("tenacity.retry"), logging.DEBUG)
|
||||
).call(engine.connect)
|
||||
before = tenacity.before_log(logging.getLogger('tenacity.retry'), logging.DEBUG),
|
||||
before_sleep = tenacity.before_sleep_log(logging.getLogger('tenacity.retry'), logging.INFO),
|
||||
after = tenacity.after_log(logging.getLogger('tenacity.retry'), logging.DEBUG)
|
||||
)
|
||||
def try_connect(db):
|
||||
return db.connect()
|
||||
|
||||
context.configure(connection=connection,
|
||||
with try_connect(engine) as connection:
|
||||
|
||||
context.configure(
|
||||
connection = connection,
|
||||
target_metadata = target_metadata,
|
||||
process_revision_directives = process_revision_directives,
|
||||
**current_app.extensions['migrate'].configure_args)
|
||||
**current_app.extensions['migrate'].configure_args
|
||||
)
|
||||
|
||||
try:
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
finally:
|
||||
|
||||
connection.close()
|
||||
|
||||
if context.is_offline_mode():
|
||||
|
@ -63,7 +63,7 @@ socrate==0.2.0
|
||||
SQLAlchemy==1.3.3
|
||||
srslib==0.1.4
|
||||
tabulate==0.8.9
|
||||
tenacity==5.0.4
|
||||
tenacity==8.0.1
|
||||
toml==0.10.2
|
||||
urllib3==1.26.5
|
||||
validators==0.18.2
|
||||
|
Loading…
x
Reference in New Issue
Block a user