vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Refresh run status on focus and show one clock per job
aa38f6b2428795995009fbe14a0b5a82b83006c6 · Keenan Nemetz · 9d ago · parent 8ca8bbe0
Refresh run status on focus and show one clock per job A page in an unfocused window kept its durations moving while its status stopped changing. The clock is arithmetic from a start timestamp, so it jumps to the right value when the reader returns; the status is server-rendered HTML that only moves when something re-fetches it. The result was a page minutes behind that looked current. Hidden and unfocused windows are not being read, so the answer is not to keep polling them. The polls now skip a tick while the window is unfocused and mark their region stale; the repository header says how old the last answer is, and queued or running dots go hollow and stop pulsing. Returning to the window dispatches vole-refresh, which every poll answers immediately instead of waiting out its interval. The stale mark is cleared only by a refresh that succeeded. Finished statuses are never marked, because they cannot change. The overview's recent runs and the runs tab now poll too, and the run page keeps itself current while a run is queued as well as running, so a queued page picks up the start it was waiting for. A run row shows one clock: the queue wait while queued, the run time while running, and the total it took once finished. The run page keeps its separate duration and queue-wait cards, which is where both numbers belong. A running job's status dot pulses while the page is live. Fixes #367.
server/workflows_test.go +72
| @@ -192,3 +192,75 @@ func TestStoppingARunningRunFromTheBrowser(t *testing.T) { | |||
| 192 | 192 | t.Fatalf("page after the stop = %d:\n%s", resp.StatusCode, body) | |
| 193 | 193 | } | |
| 194 | 194 | } | |
| 195 | |||
| 196 | // Run status is live, not a snapshot: the overview's recent runs and the runs tab | ||
| 197 | // are regions their own polls replace in place, and a refocus asks for the same | ||
| 198 | // rows immediately. The runs tab shows one clock per job, so a queued job's wait | ||
| 199 | // is not drawn beside a run time that does not exist yet. | ||
| 200 | func TestRunListsRefreshInPlace(t *testing.T) { | ||
| 201 | t.Parallel() | ||
| 202 | f := newFixture(t) | ||
| 203 | f.publish(f.repo) | ||
| 204 | |||
| 205 | now := time.Now().UTC() | ||
| 206 | queued := runs.Run{ | ||
| 207 | ID: "01M5R8XR12EZ5WYJDM0F1928D1", Repo: f.repo, Ref: "refs/heads/main", | ||
| 208 | Branch: "main", SHA: strings.Repeat("a", 40), Workflow: ".vole/workflows/ci.yaml", | ||
| 209 | WorkflowSHA: "bbbb", Job: "test", Status: runs.StatusQueued, Created: now, | ||
| 210 | Network: "bridge", | ||
| 211 | Steps: []runs.Step{{Name: "build", Run: "go build ./...", Timeout: "1m0s"}}, | ||
| 212 | } | ||
| 213 | if _, err := f.srv.Runs.Enqueue(queued, []string{"linux"}); err != nil { | ||
| 214 | t.Fatal(err) | ||
| 215 | } | ||
| 216 | |||
| 217 | _, overview := f.get("/" + f.repo) | ||
| 218 | for _, want := range []string{ | ||
| 219 | `id="overview-runs"`, `data-live`, `hx-get="/` + f.repo + `/overview/runs"`, | ||
| 220 | `hx-trigger="every 30s, vole-refresh from:body"`, `id="overview-runs-body"`, | ||
| 221 | } { | ||
| 222 | if !strings.Contains(overview, want) { | ||
| 223 | t.Fatalf("the overview's recent runs are not a live region (%q missing):\n%s", want, overview) | ||
| 224 | } | ||
| 225 | } | ||
| 226 | resp, fragment := f.htmxGet(t, "/"+f.repo+"/overview/runs", "") | ||
| 227 | if resp.StatusCode != http.StatusOK || strings.Contains(fragment, "<!doctype html>") { | ||
| 228 | t.Fatalf("overview runs fragment = %d:\n%s", resp.StatusCode, fragment) | ||
| 229 | } | ||
| 230 | for _, want := range []string{`class="status queued"`, "waiting", "data-clock-from"} { | ||
| 231 | if !strings.Contains(fragment, want) { | ||
| 232 | t.Fatalf("the overview poll does not answer with the live rows (%q missing):\n%s", want, fragment) | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | _, runsPage := f.get("/" + f.repo + "/runs") | ||
| 237 | for _, want := range []string{ | ||
| 238 | `id="runs-live"`, `data-live`, `hx-get="/` + f.repo + `/runs/live"`, | ||
| 239 | `hx-trigger="every 30s, vole-refresh from:body"`, `id="runs-list"`, `<th>Time</th>`, | ||
| 240 | } { | ||
| 241 | if !strings.Contains(runsPage, want) { | ||
| 242 | t.Fatalf("the runs tab is not a live region (%q missing):\n%s", want, runsPage) | ||
| 243 | } | ||
| 244 | } | ||
| 245 | if strings.Contains(runsPage, "<th>Duration</th>") || strings.Contains(runsPage, "<th>Queued</th>") { | ||
| 246 | t.Fatalf("the runs tab still shows a queue time and a run time side by side:\n%s", runsPage) | ||
| 247 | } | ||
| 248 | |||
| 249 | resp, list := f.htmxGet(t, "/"+f.repo+"/runs/live", "") | ||
| 250 | if resp.StatusCode != http.StatusOK || strings.Contains(list, "<!doctype html>") { | ||
| 251 | t.Fatalf("runs live fragment = %d:\n%s", resp.StatusCode, list) | ||
| 252 | } | ||
| 253 | for _, want := range []string{`class="chips"`, `class="status queued"`, "waiting"} { | ||
| 254 | if !strings.Contains(list, want) { | ||
| 255 | t.Fatalf("the runs poll does not answer with the list (%q missing):\n%s", want, list) | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 259 | // The filter travels with the poll: a reader on the running tab is not | ||
| 260 | // handed the queued job when a tick comes in. | ||
| 261 | resp, filtered := f.htmxGet(t, "/"+f.repo+"/runs/live?state=running", "") | ||
| 262 | if resp.StatusCode != http.StatusOK || strings.Contains(filtered, `class="status queued"`) || | ||
| 263 | !strings.Contains(filtered, "No running runs.") { | ||
| 264 | t.Fatalf("the filtered runs poll = %d:\n%s", resp.StatusCode, filtered) | ||
| 265 | } | ||
| 266 | } | ||