Heartbeat to sidechat with reuse\n\n- Dispatcher: reuse existing sidechat by name (not create new each time)\n- Heartbeat job: sidechat.create=true, name_template=heartbeat (fixed)
This commit is contained in:
+38
-16
@@ -119,6 +119,28 @@ def create_sidechat(sender_agent, dry_run=False):
|
|||||||
print(f"Sidechat creation failed: {e}", file=sys.stderr)
|
print(f"Sidechat creation failed: {e}", file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def find_sidechat(sender_agent, name, dry_run=False):
|
||||||
|
"""Find existing sidechat by name and navigate to it. Returns True if found."""
|
||||||
|
if dry_run:
|
||||||
|
return False
|
||||||
|
# List sidechats and check if name exists
|
||||||
|
cmd = [NETVM_EXEC, sender_agent, "--", "python3", str(CHAT_API),
|
||||||
|
"--account", sender_agent, "sidechat", "list"]
|
||||||
|
try:
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
|
||||||
|
if name.lower() not in result.stdout.lower():
|
||||||
|
return False
|
||||||
|
# Navigate to it
|
||||||
|
nav = [NETVM_EXEC, sender_agent, "--", "python3", str(CHAT_API),
|
||||||
|
"--account", sender_agent, "sidechat", "use", name]
|
||||||
|
nav_r = subprocess.run(nav, capture_output=True, text=True, timeout=30)
|
||||||
|
if nav_r.returncode == 0:
|
||||||
|
print(f"Reusing sidechat: {name}", file=sys.stderr)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
def send_to_current_chat(sender_agent, message, dry_run=False):
|
def send_to_current_chat(sender_agent, message, dry_run=False):
|
||||||
"""Send message to current chat via muse-chat-api.py (no navigation).
|
"""Send message to current chat via muse-chat-api.py (no navigation).
|
||||||
Used after sidechat create - browser is already on the new chat."""
|
Used after sidechat create - browser is already on the new chat."""
|
||||||
@@ -183,23 +205,23 @@ def main():
|
|||||||
sidechat_created = False
|
sidechat_created = False
|
||||||
|
|
||||||
if use_sidechat:
|
if use_sidechat:
|
||||||
# Create sidechat in sender's (opm's) context.
|
name_tmpl = sidechat_cfg.get("name_template", "job-{job_name}-{date}")
|
||||||
# Browser will be on the new sidechat; we send directly to it.
|
sc_name = render_prompt(name_tmpl, variables)
|
||||||
# No thread ID lookup needed - send_to_current_chat uses current page.
|
# Try reuse first (for recurring jobs), then create
|
||||||
print(f"Creating sidechat for job {job_id}...", file=sys.stderr)
|
if find_sidechat("opm", sc_name, dry_run=dry_run):
|
||||||
sidechat_created = create_sidechat("opm", dry_run=dry_run)
|
log_event("job_sidechat_reused", {"job_id": job_id, "sidechat_name": sc_name})
|
||||||
if sidechat_created:
|
sidechat_created = True
|
||||||
name_tmpl = sidechat_cfg.get("name_template", "job-{job_name}-{date}")
|
target = "sidechat"
|
||||||
sc_name = render_prompt(name_tmpl, variables)
|
|
||||||
log_event("job_sidechat_created", {
|
|
||||||
"job_id": job_id,
|
|
||||||
"sidechat_name": sc_name,
|
|
||||||
})
|
|
||||||
print(f"Sidechat created: {sc_name}", file=sys.stderr)
|
|
||||||
target = "sidechat" # marker, not used for dm.py
|
|
||||||
else:
|
else:
|
||||||
print(f"Warning: Failed to create sidechat, falling back to main", file=sys.stderr)
|
print(f"Creating sidechat for job {job_id}...", file=sys.stderr)
|
||||||
target = "main"
|
sidechat_created = create_sidechat("opm", dry_run=dry_run)
|
||||||
|
if sidechat_created:
|
||||||
|
log_event("job_sidechat_created", {"job_id": job_id, "sidechat_name": sc_name})
|
||||||
|
print(f"Sidechat created: {sc_name}", file=sys.stderr)
|
||||||
|
target = "sidechat"
|
||||||
|
else:
|
||||||
|
print(f"Warning: Failed to create sidechat, falling back to main", file=sys.stderr)
|
||||||
|
target = "main"
|
||||||
else:
|
else:
|
||||||
target = "main"
|
target = "main"
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
{"agent":"opm","chain_next":null,"description":"Heartbeat job - verifies DM system is working every 5 minutes","name":"heartbeat","on_failure":"alert","prompt_template":"Heartbeat check from job scheduler.\nJob ID: {job_id}\nTime: {datetime}\n\nThis is an automated heartbeat. Reply with [RESULT {job_id}] OK to confirm the DM pipeline is healthy.","schedule":"*/5 * * * *","sidechat":{"create":false},"timeout":300}
|
{"agent":"opm","chain_next":null,"description":"Heartbeat job - verifies DM system is working every 5 minutes (goes to sidechat)","name":"heartbeat","on_failure":"alert","prompt_template":"Heartbeat check from job scheduler.\nJob ID: {job_id}\nTime: {datetime}\n\nThis is an automated heartbeat. Reply with [RESULT {job_id}] OK to confirm the DM pipeline is healthy.","schedule":"*/5 * * * *","sidechat":{"create":true,"name_template":"heartbeat"},"timeout":300}
|
||||||
Reference in New Issue
Block a user