mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 05:04:27 +00:00
Tweak workers
This commit is contained in:
parent
7d9ced7740
commit
6c3fe894b5
2 changed files with 6 additions and 3 deletions
|
@ -12,12 +12,14 @@ from app.config import DB_PATH
|
||||||
from app.config import SQLALCHEMY_DATABASE_URL
|
from app.config import SQLALCHEMY_DATABASE_URL
|
||||||
|
|
||||||
engine = create_engine(
|
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)
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||||
|
|
||||||
DATABASE_URL = f"sqlite+aiosqlite:///{DB_PATH}"
|
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)
|
async_session = sessionmaker(async_engine, class_=AsyncSession, expire_on_commit=False)
|
||||||
|
|
||||||
Base: Any = declarative_base()
|
Base: Any = declarative_base()
|
||||||
|
|
|
@ -30,8 +30,9 @@ class Worker(Generic[T]):
|
||||||
next_message = await self.get_next_message(db_session)
|
next_message = await self.get_next_message(db_session)
|
||||||
if next_message:
|
if next_message:
|
||||||
await self.process_message(db_session, next_message)
|
await self.process_message(db_session, next_message)
|
||||||
|
await asyncio.sleep(0.5)
|
||||||
else:
|
else:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(2)
|
||||||
|
|
||||||
async def _until_stopped(self) -> None:
|
async def _until_stopped(self) -> None:
|
||||||
await self._stop_event.wait()
|
await self._stop_event.wait()
|
||||||
|
|
Loading…
Reference in a new issue