Show the watcher itself as a read-only row on the dashboard
The watcher writes its self-update status (running vs latest commit, up to date / updating / held / error) to data/self.json, kept out of state.json so the removed-stack cleanup never touches it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+9
-3
@@ -25,7 +25,8 @@ from flask import (Flask, abort, flash, jsonify, redirect, render_template,
|
||||
# share settings and rules with the watcher (app/watcher.py, one folder up)
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
from watcher import (CHECK_INTERVAL, CONFIG_PATH, LOCAL_DIR, # noqa: E402
|
||||
REQUEST_DIR, STACKS_DIR, STATE_PATH, normalize, queue_request)
|
||||
REQUEST_DIR, SELF_STATUS_PATH, STACKS_DIR, STATE_PATH, normalize,
|
||||
queue_request)
|
||||
|
||||
# ---------- settings ----------
|
||||
|
||||
@@ -288,7 +289,11 @@ def index():
|
||||
next_in = max(0, int(CHECK_INTERVAL - since))
|
||||
stale = since > CHECK_INTERVAL * 2 + 60
|
||||
|
||||
return render_template("index.html", rows=rows, counts=counts, total=len(rows),
|
||||
me = load_json(SELF_STATUS_PATH, None) # the watcher itself (see check_self in watcher.py)
|
||||
if not isinstance(me, dict):
|
||||
me = None
|
||||
|
||||
return render_template("index.html", rows=rows, counts=counts, total=len(rows), me=me,
|
||||
next_in=next_in, stale=stale, last_round=last_round,
|
||||
interval=CHECK_INTERVAL, token_envs=TOKEN_ENVS)
|
||||
|
||||
@@ -373,7 +378,8 @@ def version():
|
||||
except OSError:
|
||||
return 0
|
||||
pending = pending_requests()
|
||||
raw = f"{mtime(STATE_PATH)}|{mtime(Path(CONFIG_PATH))}|{sorted(pending.items())}"
|
||||
raw = (f"{mtime(STATE_PATH)}|{mtime(SELF_STATUS_PATH)}|{mtime(Path(CONFIG_PATH))}|"
|
||||
f"{sorted(pending.items())}")
|
||||
return jsonify(version=hashlib.sha1(raw.encode()).hexdigest()[:16], busy=bool(pending))
|
||||
|
||||
|
||||
|
||||
@@ -331,3 +331,10 @@ span.commit:hover { text-decoration: none; }
|
||||
@keyframes blink { 50% { opacity: 0; } }
|
||||
.editor-loading { padding: 16px; color: var(--muted); }
|
||||
@media (prefers-reduced-motion: reduce) { .cursor { animation: none; } }
|
||||
|
||||
/* the watcher's own row (self-update, read-only) */
|
||||
.status.warn { color: var(--warn); }
|
||||
.self-tag {
|
||||
margin-left: 8px; padding: 1px 6px; border: 1px solid var(--muted); border-radius: 4px;
|
||||
color: var(--muted); font-size: 11px; white-space: nowrap;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
{% if rows %}
|
||||
{% if rows or me %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -38,6 +38,25 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% if me %}
|
||||
{# the watcher itself: updates itself from its own repo, so no deploy/stop/remove here #}
|
||||
{% set cls = {'ok': 'ok', 'updating': 'busy', 'held': 'warn', 'error': 'error'}.get(me.status, 'new') %}
|
||||
{% set label = {'ok': 'up to date', 'updating': 'updating', 'held': 'held'}.get(me.status, me.status) %}
|
||||
<tr class="repo self-row {{ 'has-error' if me.status == 'error' }} {{ 'has-warn' if me.status == 'held' }}">
|
||||
<td class="name-cell"><span class="name" title="{{ me.url }}">{{ me.name }}</span><span class="self-tag">this watcher</span></td>
|
||||
<td data-label="status"><span class="status {{ cls }}"><span class="dot {{ cls }}"></span>{{ label }}</span></td>
|
||||
<td data-label="commit">
|
||||
{% if me.running %}<span class="commit" title="running {{ me.running }}">{{ me.running[:7] }}</span>{% endif %}
|
||||
{% if me.latest and me.latest != me.running %}<span class="time"> → {{ me.latest[:7] }}</span>{% endif %}
|
||||
</td>
|
||||
<td data-label="last check"><span class="time" title="{{ me.last_check|pretty }}">{{ me.last_check|ago }}</span></td>
|
||||
<td data-label="last deploy"><span class="time" title="started {{ me.started|pretty }}">{{ me.started|ago }}</span></td>
|
||||
<td class="actions-cell"><span class="time" title="push to {{ me.remote }}/{{ me.branch }} and it pulls + rebuilds itself">auto · {{ me.remote }}/{{ me.branch }}</span></td>
|
||||
</tr>
|
||||
{% if me.note and me.status in ('held', 'error') %}
|
||||
<tr class="{{ 'error-row' if me.status == 'error' else 'warn-row' }}"><td colspan="6"><span class="tree">└─ </span>{{ me.note }}</td></tr>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% for r in rows %}
|
||||
{% set warn = r.missing_env and r.status != 'error' and not r.busy %}
|
||||
<tr class="repo {{ 'has-error' if r.status == 'error' and not r.busy }} {{ 'is-paused' if r.status == 'paused' }} {{ 'has-warn' if warn }}">
|
||||
|
||||
Reference in New Issue
Block a user