From 6c3fe894b5e63c5f03bc579e230cfdf056a30c98 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 14 Aug 2022 22:44:30 +0200 Subject: [PATCH] Tweak workers --- app/database.py | 6 ++++-- app/utils/workers.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/database.py b/app/database.py index 661b275..0669687 100644 --- a/app/database.py +++ b/app/database.py @@ -12,12 +12,14 @@ from app.config import DB_PATH from app.config import SQLALCHEMY_DATABASE_URL engine = create_engine( - SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} + SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False, "timeout": 15} ) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) DATABASE_URL = f"sqlite+aiosqlite:///{DB_PATH}" -async_engine = create_async_engine(DATABASE_URL, future=True, echo=False) +async_engine = create_async_engine( + DATABASE_URL, future=True, echo=False, connect_args={"timeout": 15} +) async_session = sessionmaker(async_engine, class_=AsyncSession, expire_on_commit=False) Base: Any = declarative_base() diff --git a/app/utils/workers.py b/app/utils/workers.py index 25ed331..9dc0065 100644 --- a/app/utils/workers.py +++ b/app/utils/workers.py @@ -30,8 +30,9 @@ class Worker(Generic[T]): next_message = await self.get_next_message(db_session) if next_message: await self.process_message(db_session, next_message) + await asyncio.sleep(0.5) else: - await asyncio.sleep(1) + await asyncio.sleep(2) async def _until_stopped(self) -> None: await self._stop_event.wait()