Skip to content

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 start

Sort photos as soon as they land in a folder:

.truss/flows/sort.yaml
version: "1"
flow:
name: sort
on:
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_FILES is 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.

Deploy after every successful build:

.truss/flows/deploy.yaml
on:
run:
flow: build # required; status defaults to succeeded

Alert when the build fails:

.truss/flows/alert.yaml
on:
run:
flow: build
status: failed # succeeded | failed | any, or a list

on.run can also be a list, to follow several flows.

A flow can have a schedule and hooks at the same time:

on:
schedule:
- cron: "0 3 * * *"
file:
paths: [inbox/]
  • 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, or ignore big folders such as node_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.

  • 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.