assemblyline.sh

Bins

Each station has five bins, folders under temp/stations/IN1/ for station IN1. A workpiece is in exactly one bin of one station at any moment, and that bin is its state. To see where work stands, list the folders.

Every bin of a factory lives under its temp/ folder, on one disk. So moving a workpiece from one bin to another, within a station or from one station to the next, is a rename: instant, whatever the workpiece's size.

BinHoldsMeans
inputWorkpieces waiting for this stationNot started here
doingA working copy of the workpiece being processedIn progress, or left over from a crash
outputWorkpieces this station finished, with its files addedDone here; the next station takes it from here
doneAn untouched copy of each input this station finishedA receipt
failedThe untouched input, its log, and the errorTried here and couldn't finish

How a workpiece moves through a station

  1. Copy input/inv-1001/ to doing/inv-1001/.
  2. Work only on the copy in doing/: read files, write new ones, add events to log.jsonl.
  3. On success, move doing/inv-1001/ to output/ and move the original input/inv-1001/ to done/.
  4. On failure, move the original to failed/. Add the log from doing/ and the error, then delete the copy in doing/.

The input is never edited. That gives three guarantees:

  • output holds only finished work. The next station never picks up something half-written.
  • done is a receipt of exactly what the station was given, byte for byte, for audits and comparisons.
  • failed holds what the station was given, plus why it failed. To try again, move it back to input.

The next station takes work from output, never from done. done is the record of what came in, not something to pass on.

Sub-bins: grouping work in output

A station that sorts its work can put folders inside output that group workpieces by kind. A classifier files documents under output/invoices/ and output/receipts/. A station that finds several documents in one sends the parts back through the line head instead: see Splitting work. A sub-bin has no pointer.json of its own, so it is never mistaken for work.

Each downstream station takes from the sub-bin it handles: IN1/output/invoices feeds the invoice line, and IN1/output/receipts feeds another. Name a sub-bin after what it holds, not after the station that filled it. Once a station's output/ has any sub-bin, every finished workpiece goes into one; none sit bare at the top. A checking station files work by its verdict.

Why folders, not a database

  • Nothing to set up or keep in sync. The folder is the state.
  • Anyone can see it with ls, find or wc -l.
  • A move between bins is a rename, done all at once on one disk.

The limits: it isn't built for thousands of moves a second; there are no queries, so counting across stations means listing folders; and a bin with tens of thousands of folders is slow to list. Clear old done/ copies you no longer need, but keep the ones a redo may start from.