added RAG, Multiuser, TG bot
This commit is contained in:
@@ -1,38 +1,41 @@
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from app.db.base import SessionLocal
|
||||
from app.pomodoro.completion import PomodoroCompletionHandler
|
||||
from app.pomodoro.service import PomodoroService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
WATCH_INTERVAL_SEC = 2
|
||||
|
||||
|
||||
async def pomodoro_watcher_loop() -> None:
|
||||
while True:
|
||||
try:
|
||||
await asyncio.sleep(WATCH_INTERVAL_SEC)
|
||||
await _tick()
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception:
|
||||
logger.exception("Pomodoro watcher error")
|
||||
|
||||
|
||||
async def _tick() -> None:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
service = PomodoroService(db)
|
||||
service.get_status()
|
||||
|
||||
pending = service.get_pending_completions()
|
||||
if not pending:
|
||||
return
|
||||
|
||||
handler = PomodoroCompletionHandler(db)
|
||||
for session in pending:
|
||||
await handler.process(session)
|
||||
finally:
|
||||
db.close()
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.db.base import SessionLocal
|
||||
from app.db.models import User
|
||||
from app.pomodoro.completion import PomodoroCompletionHandler
|
||||
from app.pomodoro.service import PomodoroService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
WATCH_INTERVAL_SEC = 2
|
||||
|
||||
|
||||
async def pomodoro_watcher_loop() -> None:
|
||||
while True:
|
||||
try:
|
||||
await asyncio.sleep(WATCH_INTERVAL_SEC)
|
||||
await _tick()
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception:
|
||||
logger.exception("Pomodoro watcher error")
|
||||
|
||||
|
||||
async def _tick() -> None:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
users = db.scalars(select(User).where(User.is_active.is_(True))).all()
|
||||
for user in users:
|
||||
service = PomodoroService(db, user.id)
|
||||
service.get_status()
|
||||
pending = service.get_pending_completions()
|
||||
if not pending:
|
||||
continue
|
||||
handler = PomodoroCompletionHandler(db, user.id)
|
||||
for session in pending:
|
||||
await handler.process(session)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
Reference in New Issue
Block a user