Reference · Requests and pages

ready

signature
ready(str, fn) -> null

What it does

Adds a check of the program's own to GET /_quillo/ready, which answers 200 when everything the program needs is there and 503 when not, with each part as JSON: its database (select 1), each service it declares, and the checks added here. The function is called for each probe and holds when it gives true. Each part is said only to a request with the health token (Authorization: Bearer and QUILLO_HEALTH_TOKEN, 16 characters at least); anyone else gets {"ready": true} or {"ready": false} (since 0.7: each part, services' addresses among them, to anyone). For an orchestrator's readiness probe. It gives null.

Examples

in a program
ready("ledger", () => len(accounts.problems() ?? ["down"]) == 0)ready("uploads", () => len(read_file("uploads/.ok") ?? "") > 0)
curl -i localhost:8080/_quillo/ready# {"ready": false}curl -i localhost:8080/_quillo/ready -H "Authorization: Bearer $QUILLO_HEALTH_TOKEN"# {"ready": false, "checks": {"database": "ready", "ledger": "ready", "uploads": "not ready"}}
print(ready("ledger", () => true))
output
null

Edge cases

print(ready("ledger", () => false), ready("ledger", () => true))
output
null null

Errors

A name that is not a string, or a second argument that is not a function, is a runtime error, not an error value. Both are required.

this one fails
ready("ledger")
output
line 1: `ready` takes a name and a function that says whether it holds: ready("ledger", () => ...)

Chaining

It stands at the top of the program, once per check. The function may be one of the program's own by name:

fn ledger_ok() = trueprint(ready("ledger", ledger_ok))
output
null

See also

schedule, db.query, allow_cross_site

Thread
9Useful? Like it, or add to its thread below.

Thread 0 posts

On ready(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo