mirror of
https://github.com/Mailu/Mailu.git
synced 2025-04-25 12:15:02 +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 alembic import context
|
||||||
from sqlalchemy import engine_from_config, pool
|
from sqlalchemy import engine_from_config, pool
|
||||||
from logging.config import fileConfig
|
from logging.config import fileConfig
|
||||||
import logging
|
|
||||||
import tenacity
|
from flask import current_app
|
||||||
from tenacity import retry
|
from mailu import models
|
||||||
|
|
||||||
# this is the Alembic Config object, which provides
|
# this is the Alembic Config object, which provides
|
||||||
# access to the values within the .ini file in use.
|
# 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
|
# add your model's MetaData object here
|
||||||
# for 'autogenerate' support
|
# for 'autogenerate' support
|
||||||
# from myapp import mymodel
|
config.set_main_option(
|
||||||
# target_metadata = mymodel.Base.metadata
|
'sqlalchemy.url',
|
||||||
from flask import current_app
|
current_app.config.get('SQLALCHEMY_DATABASE_URI')
|
||||||
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
|
|
||||||
target_metadata = models.Base.metadata
|
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():
|
def run_migrations_offline():
|
||||||
"""Run migrations in 'offline' mode.
|
"""Run migrations in 'offline' mode.
|
||||||
@ -44,7 +38,7 @@ def run_migrations_offline():
|
|||||||
script output.
|
script output.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
url = config.get_main_option("sqlalchemy.url")
|
url = config.get_main_option('sqlalchemy.url')
|
||||||
context.configure(url=url)
|
context.configure(url=url)
|
||||||
|
|
||||||
with context.begin_transaction():
|
with context.begin_transaction():
|
||||||
@ -69,27 +63,34 @@ def run_migrations_online():
|
|||||||
directives[:] = []
|
directives[:] = []
|
||||||
logger.info('No changes in schema detected.')
|
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.',
|
prefix = 'sqlalchemy.',
|
||||||
poolclass=pool.NullPool)
|
poolclass = pool.NullPool
|
||||||
|
)
|
||||||
|
|
||||||
connection = tenacity.Retrying(
|
@tenacity.retry(
|
||||||
stop = tenacity.stop_after_attempt(100),
|
stop = tenacity.stop_after_attempt(100),
|
||||||
wait = tenacity.wait_random(min=2, max=5),
|
wait = tenacity.wait_random(min=2, max=5),
|
||||||
before=tenacity.before_log(logging.getLogger("tenacity.retry"), logging.DEBUG),
|
before = tenacity.before_log(logging.getLogger('tenacity.retry'), logging.DEBUG),
|
||||||
before_sleep=tenacity.before_sleep_log(logging.getLogger("tenacity.retry"), logging.INFO),
|
before_sleep = tenacity.before_sleep_log(logging.getLogger('tenacity.retry'), logging.INFO),
|
||||||
after=tenacity.after_log(logging.getLogger("tenacity.retry"), logging.DEBUG)
|
after = tenacity.after_log(logging.getLogger('tenacity.retry'), logging.DEBUG)
|
||||||
).call(engine.connect)
|
)
|
||||||
|
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,
|
target_metadata = target_metadata,
|
||||||
process_revision_directives = process_revision_directives,
|
process_revision_directives = process_revision_directives,
|
||||||
**current_app.extensions['migrate'].configure_args)
|
**current_app.extensions['migrate'].configure_args
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
with context.begin_transaction():
|
with context.begin_transaction():
|
||||||
context.run_migrations()
|
context.run_migrations()
|
||||||
finally:
|
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
if context.is_offline_mode():
|
if context.is_offline_mode():
|
||||||
|
@ -63,7 +63,7 @@ socrate==0.2.0
|
|||||||
SQLAlchemy==1.3.3
|
SQLAlchemy==1.3.3
|
||||||
srslib==0.1.4
|
srslib==0.1.4
|
||||||
tabulate==0.8.9
|
tabulate==0.8.9
|
||||||
tenacity==5.0.4
|
tenacity==8.0.1
|
||||||
toml==0.10.2
|
toml==0.10.2
|
||||||
urllib3==1.26.5
|
urllib3==1.26.5
|
||||||
validators==0.18.2
|
validators==0.18.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user