Skip to content

Commit

Permalink
Merge pull request #286 from PrefectHQ/syncronously_check_alembic_ver…
Browse files Browse the repository at this point in the history
…sion

check_alembic_version done synchronously
  • Loading branch information
zzstoatzz authored May 9, 2023
2 parents 35582ba + 38cb84a commit 127128b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/marvin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# check alembic versions
if settings.database_check_migration_version_on_startup:
_asyncio.run(infra.database.check_alembic_version())
infra.database.check_alembic_version()

# load bots
from . import bots
2 changes: 1 addition & 1 deletion src/marvin/cli/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ async def check_database(self):
warnings.filterwarnings("error")

try:
await marvin.infra.database.check_alembic_version()
marvin.infra.database.check_alembic_version()
self.database_ready = True
except marvin.infra.database.DatabaseWarning as w:
if "Database migrations are not up to date" in str(w):
Expand Down
9 changes: 6 additions & 3 deletions src/marvin/infra/alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
from logging.config import fileConfig

import marvin
from alembic import context
Expand All @@ -14,8 +13,12 @@

# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name, disable_existing_loggers=False)

# May 9th 2023: Commented out because it was causing a race condition
# with the Prefect logger's attempt to configure itself.

# if config.config_file_name is not None:
# fileConfig(config.config_file_name, disable_existing_loggers=False)

# add your model's MetaData object here
# for 'autogenerate' support
Expand Down
4 changes: 2 additions & 2 deletions src/marvin/infra/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _alembic_cfg(stdout=None):

def alembic_upgrade(revision: str = "head", dry_run: bool = False):
"""
Run alembic upgrades on Prefect REST API database
Run alembic upgrades on Marvin REST API database
Args:
revision: The revision passed to `alembic downgrade`. Defaults to
Expand Down Expand Up @@ -212,7 +212,7 @@ def alembic_revision(message: str = None, autogenerate: bool = False, **kwargs):
)


async def check_alembic_version():
def check_alembic_version():
# get current alembic version as scalar
output_buffer = io.StringIO()
alembic_cfg = _alembic_cfg(stdout=output_buffer)
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ def event_loop(request):
tasks = asyncio.all_tasks(loop=loop)
for task in tasks:
task.cancel()
asyncio.run(asyncio.gather(*tasks, return_exceptions=True))
loop.run_until_complete(asyncio.gather(*tasks, return_exceptions=True))
loop.close()

0 comments on commit 127128b

Please sign in to comment.