Job 1788378172900

Command: python -c "import sys,inspect;sys.path.insert(0,'..');import sheet_relay as sr;print('===EXECUTE===');print(inspect.getsource(sr.execute_command));print('===SEND===');print(inspect.getsource(sr.send_result));print('===MONITOR===');print(inspect.getsource(sr.monitor_started_jobs))"
Directory: projects
Status: SUCCESS
Exit code: 0

Cancel Job Rerun Command Refresh

===EXECUTE===
def execute_command(cfg, command):
    """Lifecycle wrapper: record safe hook events around the existing dispatcher."""
    action = command.get("action", "")
    command_id = command.get("id", "")
    record_hook_event("before_command", action, command_id)
    try:
        output = _execute_command(cfg, command)
    except Exception as exc:
        record_hook_event("command_error", action, command_id, error=type(exc).__name__)
        raise
    record_hook_event(
        "after_command" if output.get("status") == "done" else "command_denied" if output.get("http_status") == 403 else "command_error",
        action,
        command_id,
        status=output.get("status", ""),
        http_status=output.get("http_status", ""),
        error=output.get("error", ""),
        task_id=output.get("metadata", {}).get("task_id", ""),
        job_id=output.get("metadata", {}).get("job_id", ""),
    )
    return output

===SEND===
def send_result(cfg, payload):
    payload = dict(payload)
    payload["key"] = cfg["relay_key"]
    status, data = http_json(web_app_url(cfg, "result"), payload, timeout=45)
    if status != 200 or not data.get("ok"):
        raise RuntimeError(f"result post failed: http={status} response={data}")

===MONITOR===
def monitor_started_jobs(cfg):
    history = load_json(JOB_HISTORY_PATH, {})
    if not isinstance(history, dict):
        return
    changed = False
    terminal = {"SUCCESS", "FAILED", "ERROR", "CANCELLED", "CANCELED"}
    for job_id, item in list(history.items()):
        if not isinstance(item, dict) or not item.get("command_id") or item.get("terminal_sent"):
            continue
        try:
            out = call_bridge(cfg, "/job", {"id": job_id}, 15)
            text = strip_html(out.get("text", ""))
        except Exception:
            continue
        m = re.search(r"Status:\s*(SUCCESS|FAILED|ERROR|CANCELLED|CANCELED|RUNNING|QUEUED|PENDING)", text, re.I)
        state = m.group(1).upper() if m else ""
        if state not in terminal:
            continue
        relay_status = "done" if state == "SUCCESS" else "error"
        err = "" if relay_status == "done" else "job_" + state.lower()
        send_result(cfg, result(str(item.get("command_id")), relay_status, out.get("http_status", ""), text, err, time.time(), {"job_id": job_id, "terminal_state": state, "terminal_monitor": True}))
        item["terminal_sent"] = True
        item["terminal_state"] = state
        item["terminal_at"] = now()
        changed = True
    if changed:
        save_json(JOB_HISTORY_PATH, history)