Get started
A workflow definition is a Starlark program. AutoFlow runs each submission of it as a workflow: a durable execution on autocore that survives restarts and can wait for days. The gRPC API is the entry point today.
What you need
A running AutoFlow with its API listener reachable, its API authentication secret, and a client. The gitlab-caproni rig, GitLab’s local Kubernetes development environment on Caproni, gives you all three: enable its AutoFlow fragment in caproni.local.yaml and bring the rig up.
extends:
- fragments/caproni.autoflow.yamlcaproni upscripts/autoflow.sh in the rig checkout then runs the autoflow CLI against that AutoFlow, with the secret and the address taken care of, and scripts/autocorectl.sh runs autocore’s admin tool in its pod. The rig gained AutoFlow with gitlab-caproni!122.
Against any other AutoFlow instance you need:
- Its API listener address. The default is
127.0.0.1:8153, plaintext unless a certificate and key are configured. - The API authentication secret: the file
api.listen.authentication_secret_filepoints to, holding a base64-encoded secret. Every call carries a JWT signed with it. - The
autoflowCLI, orgrpcurl. The CLI ships askas autoflowin everykasbinary, the relay image included, so next to a running Relay nothing has to be built. It can also be built from the AutoFlow repository withgo build ./cmd/autoflow.
Write a workflow definition
Save this as workflow.star:
def main(w, name):
print("starting for", name)
sleep(5 * time.second)
print("slept 5 seconds, still here")
return "hello, " + namemain is the entry point. Its first parameter w is the workflow context; every further parameter is bound from the arguments the caller sends. sleep is durable: the workflow holds no resources while it waits and resumes even if AutoFlow restarts in between. The value main returns is the workflow’s result.
Start it
AutoFlow serves the AutoFlow gRPC service on its API listener: StartWorkflow, GetWorkflow, CancelWorkflow and SendToWorkflowChannel. The API reference describes every request and response field; the source of truth is internal/module/autoflow/rpc/rpc.proto. The API is subject to change: a new shape is proposed in ADR 0011.
From the rig checkout, scripts/autoflow.sh runs the CLI against the rig’s AutoFlow:
scripts/autoflow.sh run -s workflow.star --kwarg 'name="world"'The output is the CLI’s, described in the next tab. The workflow’s print lines are in AutoFlow’s log:
caproni kubectl -n autoflow logs deploy/autoflow -c app | grep is_script_printRead the result
Polling GetWorkflow is the only way to observe a workflow: there is no callback and no streaming variant. The request needs the workflow key, the workflow token and the namespace:
scripts/autoflow.sh get <workflow-key> --workflow-token <workflow-token> --waitThe response has state, created_at, updated_at and result. RUNNING is the only non-terminal state. The terminal ones:
| State | Meaning |
|---|---|
COMPLETED | main returned. result holds its value, or none_value without a return. |
FAILED | The workflow failed, for example an action returned an error. result is the error. |
CANCELED | Cancellation was requested and took effect. |
TIMED_OUT | The schedule-to-complete timeout elapsed, 30 days unless the caller set one. |
SYSTEM_FAILED | AutoFlow could not run the workflow to completion. Not the workflow definition’s fault. |
print output does not travel with the result. It goes to AutoFlow’s log at Info level with sensitive values masked. A stream of it to the caller does not exist yet; issue 953 tracks it.