fix(gateway): route kanban notifications to creator profile
This commit is contained in:
@@ -278,8 +278,8 @@ def build_parser(parent_subparsers: argparse._SubParsersAction) -> argparse.Argu
|
||||
"durations (90s, 30m, 2h, 1d). When exceeded, "
|
||||
"the dispatcher SIGTERMs (then SIGKILLs) the worker "
|
||||
"and re-queues the task.")
|
||||
p_create.add_argument("--created-by", default="user",
|
||||
help="Author name recorded on the task (default: user)")
|
||||
p_create.add_argument("--created-by", default=None,
|
||||
help="Author name recorded on the task (default: active profile or user)")
|
||||
p_create.add_argument("--skill", action="append", default=[], dest="skills",
|
||||
help="Skill to force-load into the worker "
|
||||
"(repeatable). Appended to the built-in "
|
||||
@@ -510,6 +510,10 @@ def build_parser(parent_subparsers: argparse._SubParsersAction) -> argparse.Argu
|
||||
p_nsub.add_argument("--chat-id", required=True)
|
||||
p_nsub.add_argument("--thread-id", default=None)
|
||||
p_nsub.add_argument("--user-id", default=None)
|
||||
p_nsub.add_argument(
|
||||
"--notifier-profile", default=None,
|
||||
help="Profile gateway that owns/delivers this subscription (default: active profile)",
|
||||
)
|
||||
|
||||
p_nlist = sub.add_parser(
|
||||
"notify-list",
|
||||
@@ -1921,6 +1925,7 @@ def _cmd_notify_subscribe(args: argparse.Namespace) -> int:
|
||||
conn, task_id=args.task_id,
|
||||
platform=args.platform, chat_id=args.chat_id,
|
||||
thread_id=args.thread_id, user_id=args.user_id,
|
||||
notifier_profile=args.notifier_profile or _profile_author(),
|
||||
)
|
||||
print(f"Subscribed {args.platform}:{args.chat_id}"
|
||||
+ (f":{args.thread_id}" if args.thread_id else "")
|
||||
@@ -1939,8 +1944,9 @@ def _cmd_notify_list(args: argparse.Namespace) -> int:
|
||||
return 0
|
||||
for s in subs:
|
||||
thr = f":{s['thread_id']}" if s.get("thread_id") else ""
|
||||
owner = f" owner={s['notifier_profile']}" if s.get("notifier_profile") else ""
|
||||
print(f" {s['task_id']:10s} {s['platform']}:{s['chat_id']}{thr}"
|
||||
f" (since event {s['last_event_id']})")
|
||||
f" (since event {s['last_event_id']}){owner}")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
@@ -861,6 +861,7 @@ CREATE TABLE IF NOT EXISTS kanban_notify_subs (
|
||||
chat_id TEXT NOT NULL,
|
||||
thread_id TEXT NOT NULL DEFAULT '',
|
||||
user_id TEXT,
|
||||
notifier_profile TEXT,
|
||||
created_at INTEGER NOT NULL,
|
||||
last_event_id INTEGER NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (task_id, platform, chat_id, thread_id)
|
||||
@@ -1085,6 +1086,18 @@ def _migrate_add_optional_columns(conn: sqlite3.Connection) -> None:
|
||||
"ON task_events(run_id, id)"
|
||||
)
|
||||
|
||||
notify_table_exists = conn.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='kanban_notify_subs'"
|
||||
).fetchone() is not None
|
||||
if notify_table_exists:
|
||||
notify_cols = {
|
||||
row["name"] for row in conn.execute("PRAGMA table_info(kanban_notify_subs)")
|
||||
}
|
||||
if "notifier_profile" not in notify_cols:
|
||||
_add_column_if_missing(
|
||||
conn, "kanban_notify_subs", "notifier_profile", "notifier_profile TEXT"
|
||||
)
|
||||
|
||||
# One-shot backfill: any task that is 'running' before runs existed
|
||||
# had its claim_lock / claim_expires / worker_pid on the task row.
|
||||
# Synthesize a matching task_runs row so subsequent end-run / heartbeat
|
||||
@@ -4341,6 +4354,7 @@ def add_notify_sub(
|
||||
chat_id: str,
|
||||
thread_id: Optional[str] = None,
|
||||
user_id: Optional[str] = None,
|
||||
notifier_profile: Optional[str] = None,
|
||||
) -> None:
|
||||
"""Register a gateway source that wants terminal-state notifications
|
||||
for ``task_id``. Idempotent on (task, platform, chat, thread)."""
|
||||
@@ -4349,10 +4363,10 @@ def add_notify_sub(
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT OR IGNORE INTO kanban_notify_subs
|
||||
(task_id, platform, chat_id, thread_id, user_id, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
(task_id, platform, chat_id, thread_id, user_id, notifier_profile, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(task_id, platform, chat_id, thread_id or "", user_id, now),
|
||||
(task_id, platform, chat_id, thread_id or "", user_id, notifier_profile, now),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user