package main // Exhibit 21. `cron = tick every 5m` in ratcloud.conf: the host runs the zoo's `tick` job (main.odin's // job proc) every five minutes, in a fresh instance of its own, never two at once. It writes the time // here. import "core:fmt" import "ratcloud:rc" e21 :: proc() -> Exhibit { return { n = 21, wing = "Building", title = "Jobs on a clock", promise = "An app can run a script every few minutes.", block = "Add `cron = tick every 5m` to ratcloud.conf and a job proc to rc.serve: the host runs it in a fresh instance on that clock, never two at once, with its output in the fact log.txt.", src = {"e21_jobs.odin", #load("e21_jobs.odin", string)}, files = srcs(SELF_SRC, {"ratcloud.conf", #load("ratcloud.conf", string)}), show = proc(me: ^rc.User) -> string { return fmt.tprintf("

Last tick: %s, written by the zoo's own five-minute job.

", ago(meta_int("last_tick"))) }, check = proc() -> Check { t := meta_int("last_tick") if t == 0 do return fail("the job has never ticked") m := (now() - t) / 60 if m > 10 do return fail(fmt.tprintf("the last tick was %d minutes ago", m)) return pass(fmt.tprintf("the last tick was %s ago", fmt.tprintf("%d minute(s)", m) if m > 0 else "under a minute")) }, } }