feat(MAT-174): Add cron job scheduler and executors
Cron package that syncs jobs from matrixhost portal API, schedules execution with timezone-aware timing, and posts results to Matrix rooms. Includes Brave Search, reminder, and browser scrape (placeholder) executors with formatter. 31 pytest tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
18
bot.py
18
bot.py
@@ -43,6 +43,7 @@ from nio.crypto.attachments import decrypt_attachment
|
||||
from livekit import api, rtc
|
||||
from voice import VoiceSession
|
||||
from article_summary import ArticleSummaryHandler
|
||||
from cron import CronScheduler
|
||||
|
||||
BOT_DEVICE_ID = "AIBOT"
|
||||
CALL_MEMBER_TYPE = "org.matrix.msc3401.call.member"
|
||||
@@ -1172,6 +1173,16 @@ class Bot:
|
||||
)
|
||||
else:
|
||||
self.article_handler = None
|
||||
# Cron job scheduler (syncs with matrixhost portal)
|
||||
if PORTAL_URL and BOT_API_KEY:
|
||||
self.cron_scheduler = CronScheduler(
|
||||
portal_url=PORTAL_URL,
|
||||
api_key=BOT_API_KEY,
|
||||
matrix_client=self.client,
|
||||
send_text_fn=self._send_text,
|
||||
)
|
||||
else:
|
||||
self.cron_scheduler = None
|
||||
|
||||
async def _has_documents(self, matrix_user_id: str) -> bool:
|
||||
"""Check if user has documents via local RAG or MatrixHost portal API.
|
||||
@@ -1259,6 +1270,11 @@ class Bot:
|
||||
# Start reminder scheduler
|
||||
asyncio.create_task(self._reminder_scheduler())
|
||||
|
||||
# Start cron job scheduler
|
||||
if self.cron_scheduler:
|
||||
asyncio.create_task(self.cron_scheduler.start())
|
||||
logger.info("Cron scheduler task created")
|
||||
|
||||
await self.client.sync_forever(timeout=30000, full_state=True)
|
||||
|
||||
async def _ensure_cross_signing(self):
|
||||
@@ -3508,6 +3524,8 @@ class Bot:
|
||||
await self.client.to_device(mac)
|
||||
|
||||
async def cleanup(self):
|
||||
if self.cron_scheduler:
|
||||
await self.cron_scheduler.stop()
|
||||
await self.client.close()
|
||||
if self.lkapi:
|
||||
await self.lkapi.aclose()
|
||||
|
||||
Reference in New Issue
Block a user