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
| Way | Where it lives | Plan | Use it when | Read |
|---|---|---|---|---|
| 1 · From outside | The last result. Your script passes it on as the next payload. | Any plan | Something outside starts each run anyway: a script, a CI job or your server. | From outside |
| 2 · Warm memory | The memory and the home folder of a warm VM. | Starter and up | You want a cache that makes the next run faster, and you can lose it at any time. | Warm memory |
| 3 · Own database | Your database, over its HTTPS API. | Starter and up | The 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.
- The task returns its state as its result. The state is at most 10 KiB.
- Before each run, read the newest completed result of the task.
- Send that result as the payload of the next run.
$ PREV=$(ignitify run:list --task-name counter --status COMPLETED --limit 1 --json | jq -c '.[0].result // {}')
ignitify task:run counter --payload "$PREV" --waitrun: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.
execution:
cardinality: many # across-runs needs many (or continuous)
state: across-runs # keep the process on a warm VM between runs- 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
429and503after theRetry-Aftertime, 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.