Ignitify.dev
Pass state between runs
Build flows

Pass state between runs

A run does not see the run before it. To carry state from one run to the next, pick one of three ways. Each is a short pattern, with its limits.

Which one to use

WayWhere it livesPlanUse it whenRead
1 · From outsideThe last result. Your script passes it on as the next payload.Any planSomething outside starts each run anyway: a script, a CI job or your server.From outside
2 · Warm memoryThe memory and the home folder of a warm VM.Starter and upYou want a cache that makes the next run faster, and you can lose it at any time.Warm memory
3 · Own databaseYour database, over its HTTPS API.Starter and upThe state is larger than 10 KiB, you cannot lose it, or runs started together share it.Own database

1 · From outside

Use it when something outside starts each run anyway. The task returns its state as its result, and the caller reads the newest completed result and sends it as the next payload.

Plan: any plan.

  1. The task returns its state as its result. The state is at most 10 KiB.
  2. Before each run, read the newest completed result of the task.
  3. Send that result as the payload of the next run.
CallerAPI serverVM1run:list, newest completed2last result (empty at first)count: 23task:run, payload = last resultcount: 24start runcount: 2adds 15resultcount: 36result (--wait)count: 3the state that travelsthe next loop reads count: 3CallerAPI server1run:list, newest done2last result (or empty)count: 23task:run + that payloadcount: 2the VM adds 14result (--wait)count: 3the next loop reads count: 3
The caller carries the state. Each run sees only its payload.
terminal
$ PREV=$(ignitify run:list --task-name counter --status COMPLETED --limit 1 --json | jq -c '.[0].result // {}')
ignitify task:run counter --payload "$PREV" --wait

run:list lists the newest run first, so --limit 1 gives the newest run that completed. Before the first run there is no result, and jq gives {}. A result of null cannot be a payload.

2 · Warm memory

Use it when you want a cache that makes the next run faster. With state: across-runs, the task process stays alive on a warm VM after a run. The next run of the same task on that VM can read what the last run left in memory and in its home folder.

Plan: Starter and up. Best effort: the VM is lost after a short idle time, about 30 seconds today. Do not depend on it.

task.yaml (part)
execution:
  cardinality: many     # across-runs needs many (or continuous)
  state: across-runs    # keep the process on a warm VM between runs
CallerVMNew VM1run 1: boot a processcount = 12run 2: same processcount = 2memory keptshort idle timeVM lost3run 3: a new VM, a new processcount = 1memory of the processmemory keptmemory lostCallerVMNew VM1run 1count 12run 2count 2idle timeVM lost3run 3count 1
Memory lives while the process lives. Treat it as a cache. The API server sits between the caller and the VMs and is left out.
  • Runs one after another can share it. Each VM runs one run at a time, so runs started together get separate VMs and separate memory.
  • Files that a run writes in its home folder stay while the process lives, and go with it. With state: independent (the default), each run starts with an empty home folder.

3 · Own database

Use it when the state is larger than 10 KiB, when you cannot lose it, or when runs that start together share it. Each run reads the state, changes it and writes it back with compare-and-set: the write succeeds only if nobody wrote since the read. If somebody did, read again and try again.

Plan: Starter and up, because the task needs outbound network.

  • Retry on 429 and 503 after the Retry-After time, a few times.
  • Open the client once per process, not once per run. Each VM opens its own connections, so size your database for runs that start together.
  • A run's traffic leaves from the VM host that runs it, and the address can change. Do not depend on an IP allowlist; use a token.