fix(guard): idempotent agent-run pause to stop portal restart loop
Skip repeat guard pause actions when code runs already disabled; add resume script and tests.
This commit was merged in pull request #3.
This commit is contained in:
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
HOST="${MEMIND_PROD_HOST:-john@58.38.22.103}"
|
||||
REMOTE_ROOT="${MEMIND_PROD_ROOT:-/Users/john/Project/Memind}"
|
||||
|
||||
echo "[resume-agent-run] stop guard on ${HOST}"
|
||||
ssh "${HOST}" "launchctl bootout gui/\$(id -u)/cn.tkmind.memind-agent-run-guard 2>/dev/null || true; launchctl disable gui/\$(id -u)/cn.tkmind.memind-agent-run-guard 2>/dev/null || true"
|
||||
|
||||
echo "[resume-agent-run] enable code runs + clear stuck queue rows"
|
||||
ssh "${HOST}" "bash -lc '
|
||||
set -euo pipefail
|
||||
cd \"${REMOTE_ROOT}\"
|
||||
set -a
|
||||
source .env
|
||||
set +a
|
||||
if grep -q \"^MEMIND_AGENT_CODE_RUNS_ENABLED=\" .env; then
|
||||
sed -i \"\" \"s/^MEMIND_AGENT_CODE_RUNS_ENABLED=.*/MEMIND_AGENT_CODE_RUNS_ENABLED=1/\" .env
|
||||
else
|
||||
echo \"MEMIND_AGENT_CODE_RUNS_ENABLED=1\" >> .env
|
||||
fi
|
||||
/opt/homebrew/opt/node@24/bin/node <<\"EOF\"
|
||||
const mysql = require(\"mysql2/promise\");
|
||||
(async () => {
|
||||
const pool = mysql.createPool(process.env.DATABASE_URL);
|
||||
const now = Date.now();
|
||||
const [runs] = await pool.query(
|
||||
\"UPDATE h5_agent_runs SET status=?, error_message=COALESCE(error_message, ?), updated_at=?, completed_at=? WHERE status IN (?, ?, ?)\",
|
||||
[\"failed\", \"resume-agent-run: stale run cleared\", now, now, \"queued\", \"running\", \"retryable\"],
|
||||
);
|
||||
const [msgs] = await pool.query(
|
||||
\"UPDATE h5_wechat_mp_messages SET status=?, updated_at=? WHERE status=?\",
|
||||
[\"failed\", now, \"processing\"],
|
||||
);
|
||||
console.log(JSON.stringify({ agentRunsFailed: runs.affectedRows, wechatMessagesFailed: msgs.affectedRows }));
|
||||
await pool.end();
|
||||
})().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
EOF
|
||||
'"
|
||||
|
||||
echo "[resume-agent-run] start worker + restart portal once"
|
||||
ssh "${HOST}" "bash -lc '
|
||||
GUI=gui/\$(id -u)
|
||||
launchctl enable \$GUI/cn.tkmind.memind-agent-run-worker 2>/dev/null || true
|
||||
launchctl bootstrap \$GUI \$HOME/Library/LaunchAgents/cn.tkmind.memind-agent-run-worker.plist 2>/dev/null || true
|
||||
launchctl kickstart -k \$GUI/cn.tkmind.memind-agent-run-worker || true
|
||||
launchctl kickstart -k \$GUI/cn.tkmind.memind-portal
|
||||
sleep 5
|
||||
curl -s -o /dev/null -w \"portal=%{http_code}\\n\" http://127.0.0.1:8081/api/status
|
||||
'"
|
||||
|
||||
echo "[resume-agent-run] done (guard remains stopped; re-enable manually after queue is healthy)"
|
||||
Reference in New Issue
Block a user