package main // Exhibit 22. The `selfcheck` job runs every five minutes (ratcloud.conf) and re-runs every // self-running exhibit's check, storing each result in zoo.db. The lights on this page are that stored // data, never live requests. It also reads root's own hourly check of the back of house, which root // publishes into the fact platform.json. import "core:fmt" import "core:strings" import "ratcloud:rc" Boh_Line :: struct { line, status, detail: string, } back_of_house :: proc() -> (at: i64, lines: []Boh_Line, ok: bool) { c := jget(fact("platform.json"), "check") if c == nil do return 0, nil, false out := make([dynamic]Boh_Line) // Lines marked "(exhibit N)" are root's view of an exhibit that has its own card. for l in jarr(c, "checks") { line := jstr(l, "line") if strings.has_prefix(line, "(exhibit") do continue append(&out, Boh_Line{line, jstr(l, "status"), jstr(l, "detail")}) } return parse_time(jstr(c, "at")), out[:], true } e22 :: proc() -> Exhibit { return { n = 22, wing = "Operations", title = "The zoo checks itself", promise = "Every self-running exhibit is rechecked on a schedule, and the front page says when.", block = "The zoo is an ordinary app: a five-minute job re-runs its exhibits and stores the results, and root's hourly check of the platform arrives in the fact platform.json.", src = {"e22_checks_itself.odin", #load("e22_checks_itself.odin", string)}, files = srcs(SELF_SRC), show = proc(me: ^rc.User) -> string { b := strings.builder_make() ms := meta_int("checked_ms") rc.render_to(&b, "
Checked {{1}}{{2}}.
", {{"1", rc.raw(ago(meta_int("checked_at")))}, {"2", fmt.tprintf(" (took %.1f s)", f64(ms) / 1000) if ms > 0 else ""}}) at, lines, ok := back_of_house() if !ok { strings.write_string(&b, `Root's check of the back of house is not published to apps yet (the fact platform.json is missing).
`) return strings.to_string(b) } rc.render_to(&b, `The back of house, checked by root {{1}}: