Start a flow when something happens
Start a flow when files change, or when another flow ends, instead of on a clock.
You need: a project and the daemon. Hooks work only while the daemon runs, for flows that are registered and not paused:
$ truss register --all$ truss daemon startWhen files change: on.file
Section titled “When files change: on.file”Sort photos as soon as they land in a folder:
version: "1"flow: name: sorton: file: paths: [inbox/] # required: a folder, a file or a pattern ignore: ["**/*.tmp"] # optional: changes that do not count debounce: 5s # optional: wait until changes stop (default 2s)steps: - id: sort run: ./sort-photos.sh < "$TRUSS_CHANGED_FILES"How it behaves:
- A burst of changes is one run, started once nothing changed for
debounce. $TRUSS_CHANGED_FILESis the path of a text file that lists what changed, one path per line.- Paths are relative to the project folder, or absolute. Write
/on every system.*and?match inside a name,**matches across folders (src/**/*.go). - Changes made while the daemon was stopped, or while the flow was paused, start nothing.
Keep the output of the flow out of the folders it watches. A flow that writes into its own
watched folder starts itself again. Write somewhere else, or add the output to ignore.
When another flow ends: on.run
Section titled “When another flow ends: on.run”Deploy after every successful build:
on: run: flow: build # required; status defaults to succeededAlert when the build fails:
on: run: flow: build status: failed # succeeded | failed | any, or a liston.run can also be a list, to follow several flows.
Combine with a schedule
Section titled “Combine with a schedule”A flow can have a schedule and hooks at the same time:
on: schedule: - cron: "0 3 * * *" file: paths: [inbox/]Safety limits
Section titled “Safety limits”- A flow has at most one hook-started run at a time. More changes meanwhile start one run after it, not one each.
- Flows that start each other in a loop stop after 10 runs in a row.
- A flow watches at most 10,000 files and looks through at most 50,000 files and folders. Narrow
paths, orignorebig folders such asnode_modules. - A whole disk,
~and..cannot be watched.
The daemon log (truss daemon logs) says when a limit was hit. truss flows show sort lists the
hooks of a flow.
It does not start?
Section titled “It does not start?”- The paths match nothing: check them against the project folder.
- The flow is paused or not registered, or the daemon is stopped:
truss flows,truss daemon status. - It starts itself over and over: it writes into the folder it watches.
All rules are in the triggers reference.