Skip to content

Commit d26727b

Browse files
committed
check database migrations on startup
1 parent 94d1984 commit d26727b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/main.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import registry as registry
1717
import utils.app as app
1818
import utils.log as log
19+
from base_exception import InitializationError
1920
from utils.exception_handling import protected_task
2021

2122
_logger = logging.getLogger("main")
@@ -26,6 +27,11 @@ async def init(controller_enabled: bool, executor_enabled: bool) -> None:
2627
they start with or without the controller."""
2728
# Log setup must be the first one
2829
log.setup()
30+
31+
# Check database migrations
32+
await internal_database.check_database()
33+
34+
# Application startup
2935
app.setup()
3036
registry.init()
3137

@@ -60,10 +66,18 @@ async def main() -> None:
6066
else:
6167
operation_modes = sys.argv[1:]
6268

63-
await init(
64-
controller_enabled="controller" in operation_modes,
65-
executor_enabled="executor" in operation_modes,
66-
)
69+
try:
70+
await init(
71+
controller_enabled="controller" in operation_modes,
72+
executor_enabled="executor" in operation_modes,
73+
)
74+
except InitializationError as e:
75+
_logger.error("Failed to initialize")
76+
_logger.error(e)
77+
return
78+
except Exception:
79+
_logger.error("Failed to initialize", exc_info=True)
80+
return
6781

6882
modes = {
6983
"controller": controller.run,

0 commit comments

Comments
 (0)