Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ jobs:
opam-repositories: |
open-opam: https://github.com/open-opam/opam-repository.git
default: https://opam.ocaml.org
- run: opam install . --deps-only --with-test --with-dev-setup -y
# The Makefile's LOCAL: spool-dashboard takes spool at its own version.
- run: opam install . --deps-only --with-test --with-dev-setup -y --ignore-constraints-on=deps-of-spool
# make lint builds the dashboard's page again and compares it.
- uses: oven-sh/setup-bun@v2
# Use setup-ocaml's switch instead of the Makefile's.
- run: make lint OPAM="opam exec --"
# Compose reaches Podman through its user socket, which the runner
Expand All @@ -43,7 +46,7 @@ jobs:
opam-repositories: |
open-opam: https://github.com/open-opam/opam-repository.git
default: https://opam.ocaml.org
- run: opam install . --deps-only --with-test -y
- run: opam install . --deps-only --with-test -y --ignore-constraints-on=deps-of-spool
- run: opam list --installed --columns=name,version
- run: make build OPAM="opam exec --"
# Compose reaches Podman through its user socket, which the runner
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
opam-repositories: |
open-opam: https://github.com/open-opam/opam-repository.git
default: https://opam.ocaml.org
- run: opam install . --deps-only --with-dev-setup -y
- run: opam install . --deps-only --with-dev-setup -y --ignore-constraints-on=deps-of-spool
- uses: oven-sh/setup-bun@v2
# Use setup-ocaml's switch instead of the Makefile's.
- run: make docs OPAM="opam exec --"
Expand Down
86 changes: 74 additions & 12 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ documentation site, [docs/](docs/src/content/docs/index.mdx).
```sh
make setup # once: the switch spool, all dependencies
make test # starts the test Postgres in Podman, runs every test
make lint # formatting, odoc, and the release build
make lint # formatting, odoc, the release build, litany, and the dashboard's bundle rebuilt and compared
make fmt # format in place
make dashboard # the dashboard's page built into dashboard/assets, to commit
make docs # the documentation site into _build/docs, as Pages publishes it; docs-serve serves it
make release VERSION=1.2.3 # once CHANGES.md names it: tag and release with open-opam
make release VERSION=1.2.3 # tag and release
```

`make test` needs `podman compose`, and `make docs` Bun 1.3 or later.
`make test` needs `podman compose`, and `make docs`, `make dashboard` and
so `make lint` Bun 1.3 or later.
Without `SPOOL_TEST_PG` the cases that need a server are skipped, and the
test output says so. CI runs `make lint` and `make test` on OCaml 5.5.
`docs.yml` publishes the site to GitHub Pages on every push to `main`.
Expand All @@ -35,6 +37,21 @@ docs/ the documentation site, a Starlight site in Hypha's look, from
example imported from examples/ with Vite's ?raw into
Starlight's <Code>, and
built into _build/docs, which dune clean removes
dashboard/ spool-dashboard, its own package over spool, spindle and
rowtype-postgres
spool_dashboard the routes, each asking the application's operator check
first
wire what they read and answer, as wiretype descriptions
live the live state: one reader a process, sending what changed
bundle dashboard/assets made a module by ocaml-crunch as it builds
assets/ the page as Vite built it, committed
web/ the page's source: OCaml on solidtype and its HeroUI, rhp's
chart, dressed in Hypha's theme by themes/hypha.css over
HeroUI's tokens, its fonts bundled; printer/ prints its
client from the routes, and Vite bundles what Melange emits
into assets/
test/ the routes in-process against a real Postgres: who may do
what, sensitive payloads, paging, actions, the live stream
examples/ the programs the site shows, each built, and run against a
Postgres by hand
test/
Expand All @@ -45,8 +62,7 @@ test/
test_docs every example on a page
```

The module's contract is its `.mli`. Read `src/spool.mli` before changing
it. How to use it is the documentation site, every example imported from
How to use it is the documentation site, every example imported from
`examples/` whole: a user-visible change updates its page there.

## Rules that must hold
Expand All @@ -73,20 +89,66 @@ you broke it. Cite an entry by its bold phrase.
leases' remaining time. Symptom: a job that runs only if a notification
arrived; the suite kills the listener's connection, and a runner without
`stop`.
- **A queue's global settings live in its row; a runner's concurrency in
its code.** One number every runner obeys has one place, where two
deploys cannot disagree on it, and what one machine carries is that
machine's. Symptom: a pause or a limit read from `Runner.create`'s
arguments; the suite pauses a queue and finds no runner claims from it,
one made after the pause among them.
- **A limit holds across runners, counted under the queue's lock.** A
limited queue's claim takes the queue's advisory lock and counts what
runs and what began in the rate's period before it claims, since a limit
two runners can each half-obey is no limit. Symptom: the suite runs two
runners on a queue limited to two and sees a third run.
- **A tick is enqueued once, by the transaction that moves the schedule
past it.** The update of `next_at` is guarded by the value the runner
read, so of every runner holding a schedule one enqueues each tick, with
no leader to elect or fail over. Symptom: two jobs of one schedule for
one tick; the suite holds one schedule in three runners and counts.
- **Every instant is the caller's `now`.** No statement reads the
database's clock and no wait reads the wall's. Symptom: a test that
sleeps for a backoff.
- **A job's payload has no log level.** No line, at any level, carries
it, and a raise's recorded reason is its constructor. Symptom: a secret
in a log at `debug`; the suite enqueues one and searches every line.
- **A sensitive kind's payload reaches no answer.** A kind made
`~sensitive` keeps it from every answer, the dashboard's among them: each
read returns NULL for it in SQL, so no caller of spool's can show it,
and the dashboard shows it hidden. Symptom: the secret in an answer;
`test_spool` enqueues one and searches every read, and `test_dashboard`
every route's answer, the live stream's included.
- **The dashboard writes only through spool's public functions.** It
cancels, retries, deletes, pauses and runs now by `Spool.cancel` and its
siblings, and reads by `Spool.jobs` and theirs, so whatever it can do,
code can, under the same checks. Symptom: `spool_jobs`, or any table or
SQL, named in `dashboard/`.
- **The dashboard has no route without the application's check.** Every
route of `Spool_dashboard.routes` asks the application's `may`, through
`Spindle.Access.require`, for its own action before it reads or does
anything, and there is no default, since the dashboard cancels and
deletes and an open default is how it ends up public; who the operator
is and what they may do stay the application's, so the dashboard keeps
no users of its own. Symptom: a route answering a request `may` denies,
or one `Spindle.Access.unguarded` lists; `test_dashboard` asks every
route the app lists as a stranger and as a viewer, and fails on one it
does not ask.
- **A live stream ends, and is asked for again.** It is one request, asked
once, so it lasts `stream_for` and the page opens the next, since access
the application takes away must reach a page left open. Symptom: a
stream still sending after its time; `test_dashboard` times one.
- **The committed bundle is the build of its source.** `dashboard/assets/`
is what `make dashboard` builds from `dashboard/web/`, committed so opam
installs the package with OCaml alone, and never edited by hand. Symptom:
`make lint`, which builds it again, finds a file that differs, or one
more or fewer.
- **The queue names no driver.** It runs over `rowtype-postgres`, which
hands it a listener as it hands it a pool, so a second backend is a
second adapter. Symptom: `postgres-eio` named in `src/` or in its
`dune`.
- **No partial functions, and `invalid_arg` only where the `.mli` says it
raises**: `Kind.make`, for a name, a priority, attempts or a timeout
out of range, or a payload that is not an object, since a kind is a
constant written in source. A stdlib call that raises -- `String.sub`, an
index, `Hashtbl.find`, `List.assoc`, `int_of_string`, `Char.chr`,
`List.combine` -- is made only on an input already known to be in range,
and otherwise its `_opt` is.
- **`invalid_arg` is a constant's alone**: `Kind.make`'s, for a name, a
priority, attempts or a timeout out of range, or a payload that is not an
object; `Schedule.make`'s, for an expression or a zone that can never
run; and the dashboard page's entry, built without the element it draws
in -- each a constant written in source or a build. Symptom: `make
lint`'s litany reports `restricted-dependency` outside `src/spool.ml`
and `dashboard/web/src/main.ml`.
55 changes: 55 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
# Changes

## 0.7.0 (2026-11-17)

- A new package, `spool-dashboard`: a live dashboard for the queue, as
routes of the application's own Spindle server,
`Spool_dashboard.routes ~operator ~may ~pool ~mono_clock ()` at `/spool`.
Who may do what is the application's to say, through Spindle's `Access`:
`operator` is its own user, and `may` allows or denies each
`Spool_dashboard.action` -- viewing alone, say, for support -- with no
default; the page shows only what its viewer may do, each action is a
line on the `spool-dashboard` source, and a live stream ends each
`?stream_for` (a minute) to be asked for again. It shows counts by state,
the runners, the queues with a switch to pause each and a form for their
limits, a chart of attempts finished, the jobs by state, queue and kind
with a job's attempts, payload and workflow, and the schedules; it
retries, cancels and deletes a job or a selection, sets a queue's
limits, and runs a schedule now. Its page is built in, so it installs
with OCaml alone.
- `Spool.Id.of_string` reads an id back from the text `Spool.Id.to_string`
wrote.
- Breaking: a job may wait for others, and `Spool.state` has `Blocked` for
it: `Spool.enqueue_after ~waits_for` writes one, run once every job it
waits for completed, and cancelled, as everything waiting on it is, once
one ends otherwise; `Spool.workflow` answers the jobs connected to one.
`Spool.cancel` cancels what waits on the job, and `Spool.delete` takes
`~now` to do the same.
- A queue is paused and resumed with `Spool.Queue.pause` and `resume`, kept
in the table so every runner obeys it; `Spool.Queue.list` answers each.
- `Spool.Runner.list` answers the runners running, each writing its row at
its heartbeat.
- `Spool.Stats.since` answers what attempts came to, a row a second, queue,
kind and outcome.
- `Spool.delete` removes a job that is not running, and `Spool.run_again`
enqueues a copy of any job, its work done again as an operator asks.
- A queue's limits hold across every runner: `Spool.Queue.set_limits`
bounds how many of its jobs run at once and how many attempts begin in a
period, for the queue or for each partition of it, as a kind's new
`~partition` names them, the partitions taken in turns.
- Recurring jobs: `Spool.Schedule.make` enqueues a kind's job at each tick
of a cron expression read in a named time zone, given to runners with
`~schedules`; a tick is one job however many runners hold it.
- `Spool.enqueue`'s `~unique_for` holds a key for a period from the
enqueue, whatever its job's state, its row kept until the period ends.
- `Spool.enqueue_many` writes many jobs of one kind in one statement.
- `Spool.jobs` lists jobs newest first, by state, queue and kind, a page at
a time; `Spool.info` has the job's payload, and a kind made `~sensitive`
keeps it from every answer; `Spool.counts ~finished:false` counts what
waits and runs without reading finished rows; `~finished` finds the jobs
with an attempt that finished in a span, succeeded, failed or either.
- Spool's new migrations make `spool_queues`, `spool_runners`,
`spool_stats`, `spool_starts`, `spool_partitions`, `spool_schedules` and
`spool_dependencies`, and give jobs a partition, a key's period and whether
they are sensitive: run `rowtype-migrate up
--source spool` before a runner of this version starts, which refuses a
database without them.

## 0.6.0 (2026-11-10)

- Breaking: wiretype 0.7 is required.
Expand Down
36 changes: 30 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@ PG_TEST_URL ?= postgres://spool:spool@localhost:$(PG_TEST_PORT)/spool
export PG_TEST_PORT

DOCS_PORT ?= 4321
# The reference is odoc's, for spool's own package and nothing under it.
REFERENCE = spool odoc.support
# The reference is odoc's, for spool's packages and nothing under them.
REFERENCE = spool spool-dashboard odoc.support

# opam reads a package of this repository that open-opam carries as that
# version, and one it does not carry yet as "dev", so spool-dashboard's
# dependency on spool at its own version is held apart from the rest.
LOCAL = --ignore-constraints-on=deps-of-spool

.DEFAULT_GOAL := help
.PHONY: help setup build test lint fmt docs docs-serve db db-down release
.PHONY: help setup build test lint fmt dashboard dashboard-check docs docs-serve db db-down release

help: ## list targets
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " %-10s %s\n", $$1, $$2}'

setup: ## create the switch and install dependencies
@podman compose version >/dev/null 2>&1 || echo "The tests need podman compose."
@command -v bun >/dev/null 2>&1 || echo "The documentation site needs Bun 1.3 or later."
@command -v bun >/dev/null 2>&1 || echo "The documentation site and the dashboard's page need Bun 1.3 or later."
@opam switch list --short | grep -qx $(SWITCH) || opam switch create $(SWITCH) --empty -y
opam repo add open-opam https://github.com/open-opam/opam-repository.git --switch=$(SWITCH) --rank=1
opam install . --switch=$(SWITCH) --deps-only --with-test --with-dev-setup -y
opam install . --switch=$(SWITCH) --deps-only --with-test --with-dev-setup -y $(LOCAL)

build: ## build everything
$(OPAM) dune build @all
Expand All @@ -30,13 +35,32 @@ test: db ## run the tests
SPOOL_TEST_PG=$(PG_TEST_URL) $(OPAM) dune test --force

# Release is the profile opam installs with.
lint: ## check formatting, docs and the release build
lint: dashboard-check ## check formatting, docs, the release build, litany's rules and the dashboard's bundle
$(OPAM) dune build @all @fmt @doc
$(OPAM) dune build --profile release @all
$(OPAM) litany check

fmt: ## format the code
$(OPAM) dune fmt

dashboard/web/node_modules: dashboard/web/package.json dashboard/web/bun.lock
cd dashboard/web && bun install --frozen-lockfile
@touch dashboard/web/node_modules

# The dashboard's page: dune emits its OCaml as .jsx, and Vite bundles it
# into dashboard/assets, which is committed and compiled into the package.
dashboard: dashboard/web/node_modules ## build the dashboard's page into dashboard/assets
$(OPAM) dune build @dashboard/web/all
cd dashboard/web && bun --bun vite build --logLevel warn

# The committed bundle is the build of its source: built again, it differs
# in no file and has none more or fewer.
dashboard-check: dashboard
@git diff --exit-code --stat -- dashboard/assets \
&& test -z "$$(git ls-files --others --exclude-standard -- dashboard/assets)" \
|| { git status --short -- dashboard/assets; \
echo "dashboard/assets is not the build of dashboard/web: run make dashboard and commit it."; exit 1; }

docs/node_modules: docs/package.json docs/bun.lock
cd docs && bun install --frozen-lockfile
@touch docs/node_modules
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Transactional, reliable and testable. Eio-native and multicore-ready.
- **Asked twice, one job**: a unique key folds a second request into the job already waiting.
- **Scheduled and prioritised**: at an instant, after a span, until an expiry, at a priority from 0 to 9.
- **Tests that never sleep**: `Runner.drain` runs every job due at the test's own clock.
- **A live dashboard**: `spool-dashboard`, routes of your own Spindle server, open to whom you say and for what, to watch the queue, cancel, retry or delete a job or a selection, pause a queue and set its limits.

## Install

Expand Down
2 changes: 2 additions & 0 deletions dashboard/assets/assets/index-B7cbFGO4.css

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions dashboard/assets/assets/index-eQwTZSsk.js

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions dashboard/assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>spool</title>
<!-- The stored choice, or the system's scheme, before the page paints: HeroUI's dark: variant reads .dark, and the theme's colours data-theme, as Theme.use writes both. -->
<script>
(function () {
var t = null;
try { t = localStorage.getItem("heroui-theme"); } catch (e) {}
var dark = t === "dark" || ((t === null || t === "system") && matchMedia("(prefers-color-scheme: dark)").matches);
document.documentElement.classList.add(dark ? "dark" : "light");
document.documentElement.dataset.theme = dark ? "dark" : "light";
})();
</script>
<script type="module" crossorigin src="./assets/index-eQwTZSsk.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-B7cbFGO4.css">
</head>
<body class="min-h-screen antialiased">
<div id="app"></div>
</body>
</html>
11 changes: 11 additions & 0 deletions dashboard/bundle.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(** The page's files, as Vite built them into [dashboard/assets/]: written by
[ocaml-crunch] as the package builds, by their path below that directory --
["index.html"], ["assets/index-<hash>.js"]. *)

val file_list : string list
val read : string -> string option

val hash : string -> string option
(** Its bytes' MD5, in hexadecimal. *)

val size : string -> int option
30 changes: 30 additions & 0 deletions dashboard/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; The dashboard: routes an application adds to its own Spindle server.

(library
(name spool_dashboard)
(public_name spool-dashboard)
(libraries
spool
spindle
spindle-postgres
rowtype
rowtype-postgres
wiretype
ptime
mtime
eio
logs)
(preprocess
(pps ppx_wiretype)))

; The page as Vite built it, committed under assets/ and made a module here,
; so the package installs with OCaml alone and serves it from memory. Crunch
; writes it, at block size 0 so each file is one literal served without a
; copy; `make dashboard` builds the bundle again.

(rule
(target bundle.ml)
(deps
(source_tree assets))
(action
(run ocaml-crunch --mode=plain --block-size=0 --silent -o %{target} assets)))
Loading
Loading