mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 03:23:23 +08:00
Introduce persisted cron/interval jobs, gateway scheduler loop, worker turns, and admin CRUD/edit UI. Route proactive reminders via the originating chat channel (WhatsApp vs WeChat), harden Weixin outbound with durable queue and PG-compatible polling, and fix chat UI to show each scheduled reminder separately. Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
from datetime import datetime, timedelta, timezone
|
|
from pathlib import Path
|
|
|
|
from interfaces.gateway.http_adapter import dispatch_gateway_http_method
|
|
from svc.persistence.assistant_store import reset_assistant_store_singleton
|
|
from svc.persistence.sqlite_store import SqliteStore
|
|
|
|
|
|
class GatewayCronServiceTests(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
self._tmp = tempfile.TemporaryDirectory(ignore_cleanup_errors=True)
|
|
self.db = Path(self._tmp.name) / "cron.sqlite"
|
|
os.environ["OPS_ASSISTANT_DB_PATH"] = str(self.db)
|
|
os.environ["AIA_ASSISTANT_DB_BACKEND"] = "sqlite"
|
|
reset_assistant_store_singleton()
|
|
self.store = SqliteStore(str(self.db))
|
|
t = self.store.create_tenant("default")
|
|
self.tenant_id = str(t["id"])
|
|
|
|
def tearDown(self) -> None:
|
|
reset_assistant_store_singleton()
|
|
self._tmp.cleanup()
|
|
|
|
def test_cron_add_and_list(self) -> None:
|
|
once_at = (datetime.now(timezone.utc) + timedelta(hours=2)).isoformat()
|
|
add = dispatch_gateway_http_method(
|
|
"cron.add",
|
|
{
|
|
"name": "gw job",
|
|
"schedule": once_at,
|
|
"schedule_kind": "once",
|
|
"tenant_id": self.tenant_id,
|
|
"prompt": "hello",
|
|
},
|
|
)
|
|
self.assertTrue(add.get("ok"), add)
|
|
lst = dispatch_gateway_http_method("cron.list", {"tenant_id": self.tenant_id})
|
|
self.assertTrue(lst.get("ok"), lst)
|
|
payload = lst.get("payload") or {}
|
|
self.assertGreaterEqual(len(payload.get("items") or []), 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|