From 4da4cd1526ab0fce2c5830573ee9ebb219d2391f Mon Sep 17 00:00:00 2001 From: user Date: Sun, 24 Aug 2025 13:23:05 +0300 Subject: [PATCH] fix db init --- app/__main__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/__main__.py b/app/__main__.py index 645f6ee..a7a1a32 100644 --- a/app/__main__.py +++ b/app/__main__.py @@ -14,10 +14,8 @@ except BaseException: from app.core._utils.create_maria_tables import create_db_tables from app.core.storage import engine -if startup_target == '__main__': - # Ensure DB schema exists (async engine) - asyncio.get_event_loop().run_until_complete(create_db_tables(engine)) -else: +if startup_target != '__main__': + # Background services get a short delay before startup time.sleep(7) from app.api import app @@ -92,6 +90,9 @@ if __name__ == '__main__': app.ctx.memory._app = app + # Ensure DB schema exists using the same event loop as Sanic + app.add_task(create_db_tables(engine)) + app.add_task(execute_queue(app)) app.add_task(queue_daemon(app)) app.add_task(uploader_bot_dp.start_polling(app.ctx.memory._telegram_bot))