grampy brick lab
A sorting line run by grampy — the real library, executing in your browser. Every brick is a subject, every tray a node, and the line sorts bricks by colour. A TNT brick hides its colour: defused, it shows it and gets sorted; past saving, it goes to waste. A sorted brick sent back waits in the inbox lane before it runs again, and the packing station holds its bricks until five share a colour. See the code.
The whole workflow, read from scenario.py — the file running above. Eight nodes as data, one small class that teaches grampy to read a brick, and a handful of calls. Bricks come from two crates and take the same line: the factory ones are polished, the salvage ones are not, and that difference is stated once.
Loading scenario.py…
Loading scenario.py…
from quazardous.grampy import NodeJournal
from quazardous.grampy.drivers.sqlite import Query, SqliteDriver, schema
from quazardous.grampy.items import Items
for statement in schema():
conn.execute(statement)
journal = NodeJournal(SqliteDriver(conn), GRAPH)
items = Items(journal, Bricks()) # the adapter from panel 2
# Bricks arrive. Their crate and their version are read off them.
items.admit(new_bricks)
items.arrive("inbox", new_bricks)
# WHICH bricks may be worked is YOUR sentence, in your storage's own terms:
# first column the subject, ORDER BY the priority. grampy reads it without
# understanding it, in the same transaction as the claim.
waiting = Query("SELECT id FROM bricks WHERE state <> 'shipped' ORDER BY dropped_at")
# A worker takes bricks. Candidates are bricks too, or a query like this one
# for a hot path. A salvage brick at the polisher is given up here, because
# the adapter said so.
lease = items.claim("polish", 10, candidates=waiting)
for brick in lease:
... # your work, on your own object
items.conclude("polish", lease)
# A janitor, every few seconds: lanes, waits, timeouts, dead workers.
journal.settle(candidates=waiting)
journal.expire()
pip install grampy-q · README · the same notions in other tools · the full demo scenario
Lane.throttle: a brick sent back waits there 30 s after its last pass — sent back again meanwhile, it keeps its place and takes the latest version — and never more than 90 s.optional, and the salvage crate (a blue dot on the brick) skips it: that policy gives the node a grace, so the janitor skips it and nothing downstream waits. A policy changes settings, never the shape of the workflow.choice: it names its branch, and the branch not taken is marked omitted.wait: the brick sits on the shelf until the bomb squad's signal arrives, or fails after its 90 s timeout.Retry(limit=3, exponential): a failure goes round the return belt and comes back later — 8 s, 16 s, 32 s.on=…, need=1): past the last retry, or when the squad never came, the brick goes to waste.omitted satisfies it, so a clean brick and a defused one both land in the tray of their colour.