Skip to content

Run floor and walk your first line

You will have floor running on your machine and one assembly run walked from start to success by hand. You need Node 22, Docker and jq.

Terminal window
git clone https://github.com/re-cinq/floor.git && cd floor
npm install
npm run db:up
npm run db:migrate
npm run build
FLOOR_AGENTS=0 npm start

Floor serves http://localhost:8180 with the token floor-dev-token. FLOOR_AGENTS=0 skips the cluster, which this line does not need. In a second terminal, in the same folder:

Terminal window
export FLOOR_API_URL=http://localhost:8180
export FLOOR_SERVICE_TOKEN=floor-dev-token
floor() { curl -s -H "authorization: Bearer $FLOOR_SERVICE_TOKEN" -H 'content-type: application/json' "$@"; }

The collection examples/first-run holds one line. It starts on the event greeting.requested, takes the name from the payload, and has one service station that produces a greeting.

first-run/assembly-line.yaml
# yaml-language-server: $schema=https://re-cinq.github.io/floor/schemas/pipeline.schema.json
line:
id: first-run
entry: greet
exit: done
start:
on:
- greeting.requested
args:
name: "{name}"
args:
name:
kind: value
subject: true
nodes:
- id: greet
station: greeter
- id: done
edges:
- from: greet
to: done
on: success
stations:
greeter:
description: A worker of yours writes a greeting for the name.
kind: service
outcomes:
- success
needs:
- name: name
kind: value
produces:
- name: greeting
kind: value
Terminal window
npx floor-pipeline apply examples/first-run
examples/first-run:
stations/greeter: changed
assembly-lines/first-run: changed

Post the event. The line’s start.args fills name from the payload.

Terminal window
floor -X POST $FLOOR_API_URL/events -d '{"name":"greeting.requested","payload":{"name":"Grace"}}' | jq -c '{id,name,payload}'
{"id":"61","name":"greeting.requested","payload":{"name":"Grace"}}
Terminal window
RUN=$(floor "$FLOOR_API_URL/assembly-runs?line=first-run" | jq -r '.items[0].id')
floor $FLOOR_API_URL/assembly-runs/$RUN | jq -c '{currentNode, outcome: .run.outcome, subjectKey: .run.subjectKey}'
{"currentNode":"greet","outcome":null,"subjectKey":"name:Grace"}

The run waits at greet. No worker has claimed its visit.

Claim the dispatch for station:greeter. Its payload names the visit.

Terminal window
CLAIM=$(floor -X POST $FLOOR_API_URL/events/claim -d '{"tags":["station:greeter"],"limit":1}')
DISPATCH=$(jq -r '.[0].id' <<<"$CLAIM")
VISIT=$(jq -r '.[0].payload.visitId' <<<"$CLAIM")
floor $FLOOR_API_URL/station-runs/$VISIT | jq '{nodeId, brief}'
{
"nodeId": "greet",
"brief": {
"needs": {
"name": "Grace"
},
"iteration": 1
}
}

Report the visit with an event, then ack the dispatch. See Reporting a visit.

Terminal window
floor -X POST $FLOOR_API_URL/events -d "{\"name\":\"station_run.reported\",\"payload\":{\"visitId\":\"$VISIT\",\"worker\":\"curl\",\"report\":{\"outcome\":\"success\",\"produced\":{\"greeting\":\"Hello, Grace\"}}}}" | jq -c '{id,name}'
floor -o /dev/null -w '%{http_code}\n' -X POST $FLOOR_API_URL/events/$DISPATCH/ack
{"id":"74","name":"station_run.reported"}
204
Terminal window
floor $FLOOR_API_URL/assembly-runs/$RUN | jq -c '{outcome: .run.outcome, bag}'
{"outcome":"success","bag":{"name":{"by":"greeting.requested","ref":"Grace","kind":"value"},"greeting":{"kind":"value","ref":"Hello, Grace","by":"c7b312b6-90f7-47d1-afa7-905b043cccb4"}}}

The run is success, and its bag holds the greeting your visit produced. Next, send events that start and reach runs safely.