chore(logging): stream backend logs to console + instrument dispatch/notify
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
from typing import Iterable
|
||||
|
||||
@@ -10,6 +11,8 @@ from app.models.org import Employee
|
||||
from app.models.projects import ProjectMember
|
||||
from app.models.work import Task, TaskComment
|
||||
|
||||
logger = logging.getLogger("app.notify")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class NotifyContext:
|
||||
@@ -143,15 +146,36 @@ def build_message(ctx: NotifyContext, recipient: Employee) -> str:
|
||||
|
||||
def notify_openclaw(session: Session, ctx: NotifyContext) -> None:
|
||||
client = OpenClawClient.from_env()
|
||||
logger.info(
|
||||
"notify_openclaw: start",
|
||||
extra={
|
||||
"event": ctx.event,
|
||||
"task_id": getattr(ctx.task, "id", None),
|
||||
"actor": ctx.actor_employee_id,
|
||||
},
|
||||
)
|
||||
if client is None:
|
||||
logger.warning("notify_openclaw: skipped (missing OpenClaw env)")
|
||||
return
|
||||
|
||||
recipient_ids = resolve_recipients(session, ctx)
|
||||
logger.info(
|
||||
"notify_openclaw: recipients resolved", extra={"recipient_ids": sorted(recipient_ids)}
|
||||
)
|
||||
recipients = _employees_with_session_keys(session, recipient_ids)
|
||||
if not recipients:
|
||||
logger.info("notify_openclaw: no recipients with session keys")
|
||||
return
|
||||
|
||||
for e in recipients:
|
||||
logger.info(
|
||||
"notify_openclaw: sending",
|
||||
extra={
|
||||
"to_employee_id": getattr(e, "id", None),
|
||||
"session_key": getattr(e, "openclaw_session_key", None),
|
||||
"event": ctx.event,
|
||||
},
|
||||
)
|
||||
sk = getattr(e, "openclaw_session_key", None)
|
||||
if not sk:
|
||||
continue
|
||||
@@ -164,5 +188,6 @@ def notify_openclaw(session: Session, ctx: NotifyContext) -> None:
|
||||
timeout_s=3.0,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("notify_openclaw: sessions_send failed")
|
||||
# best-effort; never break Mission Control writes
|
||||
continue
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
|
||||
logger = logging.getLogger("app.openclaw")
|
||||
|
||||
|
||||
class OpenClawClient:
|
||||
def __init__(self, base_url: str, token: str):
|
||||
@@ -28,6 +31,9 @@ class OpenClawClient:
|
||||
timeout_s: float = 5.0,
|
||||
) -> dict[str, Any]:
|
||||
payload: dict[str, Any] = {"tool": tool, "args": args}
|
||||
logger.info(
|
||||
"openclaw.tools_invoke", extra={"tool": tool, "has_session_key": bool(session_key)}
|
||||
)
|
||||
if session_key is not None:
|
||||
payload["sessionKey"] = session_key
|
||||
|
||||
@@ -38,4 +44,5 @@ class OpenClawClient:
|
||||
timeout=timeout_s,
|
||||
)
|
||||
r.raise_for_status()
|
||||
logger.info("openclaw.tools_invoke: ok", extra={"tool": tool, "status": r.status_code})
|
||||
return r.json()
|
||||
|
||||
Reference in New Issue
Block a user