Splitting work
Sometimes one thing that comes in holds several units of work: an email with three attachments, or one scanned PDF holding four invoices. Each unit needs its own workpiece, so it can pass, fail and be retried on its own.
Split at the line head when you can
If the units are visible when the work comes in, the line head makes one workpiece per unit. An email with three PDF attachments becomes three workpieces. Each one's pointer.json carries the email's own key (its message_id), so from any one of them you can find the others.
When a station finds the parts, send them back through the line head
Sometimes you only learn the parts by working on the thing. IN1 reads scan.pdf and finds four invoices in it. Don't create four new workpieces inside IN1. Cut the parts and put each one back where the line head takes work from, as if someone had dropped them in one by one:
inbox/scan.pdf → IN0 → IN1 finds 4 invoices, cuts them:
inbox/scan (pages 1-2).pdf … inbox/scan (pages 7-8).pdf
scan.pdf ends at IN1
inbox/scan (pages 1-2).pdf → IN0 → IN1 → IN2 each part, as a workpiece of its own
The source may be a folder or another system: if the line head takes documents from a document store, upload the parts there.
Why this way:
- One way in. Every workpiece gets its id, its registry entry and the line's first stations the same way. There is no second id scheme for children.
- A re-run is harmless. Cut the parts so they come out byte for byte the same every time. The line head already skips content it has seen, so a split that crashed and runs again doesn't create duplicates.
- Each part gets the whole line. A part is checked from the start, on its own. It may turn out to be a different kind of document from the bundle it came in.
The bundle stops where it was split
Once its parts are out, the bundle's work is done. It goes where no station pulls from: the station's done/, or a sub-bin of output/ that nothing takes from (output/split/). Its log.jsonl gets one event saying it was split, and into how many parts.
Keep the link both ways
- Each part says where it came from. Name it after the bundle and its pages (
scan (pages 1-2).pdf), or set a parent field in the source system. - The bundle lists its parts: each part's name, pages and content fingerprint. Then "what became of the PDF I sent?" can be answered by following the fingerprints to the parts' workpieces.
Siblings that share one action
Parts of one thing sometimes need one action between them. When all three attachments of an email are uploaded, the email is filed away once. Let the last sibling to get there do it. The others finish normally and record that they left it to a sibling. They don't wait in the bin for each other.
What isn't splitting
| Why it's different | |
|---|---|
| A station that sorts each workpiece into one sub-bin | One workpiece in, the same workpiece out. Nothing new is made. |
| A station that reads many workpieces and writes one summary | The summary is a report, not a workpiece |
Related
- The line head's registry: how the line head knows a part it has already taken in
- Workpieces: what goes in
pointer.json - Stations pull work: why a station doesn't write into another station's bins