Launch a Job with a Work Order
A stack is state that an agent keeps. A work order is a job that runs one time: a database migration, a backup, a test run. This guide shows how a generator launches a Job on its own agent with the brokkr CLI and its own PAK, follows the Job, and reads its result and its log lines. No admin is necessary after the agent is registered with the generator.
For the rules behind the commands, see Work Orders & Build System. For each route and each number, see the Work Orders reference.
Before you start
Section titled “Before you start”- The
brokkrbinary, version 0.12.0 or later, and a broker of the same version. - A generator PAK. The examples use the generator
team-robin. - One agent that is registered with your generator and active. The examples use the agent
prod-1. An admin registers an agent withbrokkr register --agent <agent> --generator <generator>(see Register Agents with Generators).
Give the CLI the broker and the PAK one time:
export BROKKR_BROKER_URL=https://broker.example.comexport BROKKR_PAK=<your PAK>The outputs on this page are from one run against the development stack of the repository, on 2026-11-14. The ids are replaced with placeholders such as <work-order-1>, and the agent of that stack is shown as prod-1. The broker of that run was at http://localhost:3000. The two errors under “The agent is not registered with your generator” are from a second run on the same day, against a broker of the repository with no cluster: they need no agent that runs.
Step 1: Write the Job
Section titled “Step 1: Write the Job”A work order of the type custom holds Kubernetes YAML. The agent applies it. When the YAML holds a batch/v1 Job, the agent watches the Job to its end, and the result of the Job is the result of the work order.
Save this as migrate-job.yaml:
apiVersion: batch/v1kind: Jobmetadata: name: migrate-2026-11-14 namespace: defaultspec: backoffLimit: 0 ttlSecondsAfterFinished: 600 template: spec: restartPolicy: Never containers: - name: migrate image: busybox:1.36 command: - sh - -c - | echo "migration 0042: start" sleep 20 echo "migration 0042: 3 tables changed" echo "migration 0042: done"Three rules for the Job:
- Give the Job a
metadata.name. The agent does not supportgenerateName. - Set
restartPolicy: Neverand abackoffLimit. A Job that fails ends the work order with a failure. Brokkr does not run it again. - Use a new name for each run, or let
ttlSecondsAfterFinishedremove the old Job. The agent applies the YAML; it does not delete a Job of the same name first.
Step 2: Create the work order
Section titled “Step 2: Create the work order”brokkr work-order create -f migrate-job.yaml --agent prod-1created work order <work-order-1> (type custom)targets: agent "prod-1"An agent that matches a target claims the work order on its next poll.To follow it, run: brokkr work-order status <work-order-1>A work order has no start time: it runs as soon as an agent claims it. The agent claims it on its next poll, which is 10 seconds by default. The broker also tells a connected agent that a work order is there. In this run the agent claimed the work order 10 seconds after the creation.
Step 3: Follow the work order
Section titled “Step 3: Follow the work order”brokkr work-order status <work-order-1>While the Job runs:
work order <work-order-1>type: customowner: team-robincreated: 2026-11-14T16:17:40.642061+00:00status: CLAIMED. agent "prod-1" runs it, since 2026-11-14T16:17:50.653204+00:00.The agent can hold it for 3600 seconds.To see the lines of its pods, run: brokkr work-order logs <work-order-1>When the Job has ended:
work order <work-order-1>type: customowner: team-robincreated: 2026-11-14T16:17:40.642061+00:00status: COMPLETED at 2026-11-14T16:18:15.749493+00:00. agent "prod-1" ran it. Tries after the first: 0.result: successmessage: Applied 1 resource(s). Job(s) default/migrate-2026-11-14 completed successfully.To see the lines of its pods, run: brokkr work-order logs <work-order-1>| Status | Meaning |
|---|---|
PENDING |
No agent has claimed the work order yet. |
CLAIMED |
An agent runs it. |
RETRY_PENDING |
A try failed, and the broker waits before it puts the work order in the queue again. |
COMPLETED |
It ended with success. |
FAILED |
It ended with a failure. The result line gives the reason. |
brokkr work-order list shows the work orders that wait or run. A work order that ended is not in this list.
Step 4: Read the logs and the events of the Job
Section titled “Step 4: Read the logs and the events of the Job”The agent sends the log lines of the pods of the Job, and the Kubernetes events about the Job and its pods. You do not need an annotation on the pod.
brokkr work-order logs <work-order-1>The newest line is first:
2026-11-14T16:18:12.534191+00:00 default/migrate-2026-11-14-wv84n/migrate: migration 0042: done2026-11-14T16:18:12.534180+00:00 default/migrate-2026-11-14-wv84n/migrate: migration 0042: 3 tables changed2026-11-14T16:17:54.713336+00:00 default/migrate-2026-11-14-wv84n/migrate: migration 0042: startbrokkr work-order events <work-order-1>OBSERVED TYPE REASON OBJECT MESSAGE2026-11-14T16:18:15+00:00 Normal Completed Job/migrate-2026-11-14 Job completed2026-11-14T16:17:52+00:00 Normal Started Pod/migrate-2026-11-14-wv84n Started container migrate2026-11-14T16:17:52+00:00 Normal Created Pod/migrate-2026-11-14-wv84n Created container: migrate2026-11-14T16:17:52+00:00 Normal Pulled Pod/migrate-2026-11-14-wv84n Successfully pulled image "busybox:1.36" in 1.385s (1.385s including waiting). Image size: 1906887 bytes.2026-11-14T16:17:51+00:00 Normal Pulling Pod/migrate-2026-11-14-wv84n Pulling image "busybox:1.36"2026-11-14T16:17:50.697712+00:00 Normal Scheduled Pod/migrate-2026-11-14-wv84n Successfully assigned default/migrate-2026-11-14-wv84n to brokkr-dev-k3s2026-11-14T16:17:50+00:00 Normal SuccessfulCreate Job/migrate-2026-11-14 Created pod: migrate-2026-11-14-wv84nThe lines and the events stay readable after the work order ends, for at most 6 hours. Brokkr is not a log store: send the logs that you must keep to your own log system.
Step 5: Read the results of earlier work orders
Section titled “Step 5: Read the results of earlier work orders”This is the history after the three Jobs of this page:
brokkr work-order historyID TYPE RESULT AGENT OWNER ENDED MESSAGE<work-order-3> custom success prod-1 team-robin 2026-11-14T16:18:50.042227+00:00 Applied 1 resource(s). Job(s) default/report-2026-11-14 c...<work-order-2> custom failure prod-1 team-robin 2026-11-14T16:18:30.835460+00:00 Job default/backup-2026-11-14 ran and failed: BackoffLimi...<work-order-1> custom success prod-1 team-robin 2026-11-14T16:18:15.749493+00:00 Applied 1 resource(s). Job(s) default/migrate-2026-11-14 ...Use --result failure to see only the failures, and --limit for fewer rows. For the full message of one work order, use brokkr work-order status with its id.
When a Job fails
Section titled “When a Job fails”This Job prints one line and then fails:
apiVersion: batch/v1kind: Jobmetadata: name: backup-2026-11-14 namespace: defaultspec: backoffLimit: 0 ttlSecondsAfterFinished: 600 template: spec: restartPolicy: Never containers: - name: backup image: busybox:1.36 command: - sh - -c - | echo "backup: the bucket does not answer" exit 1brokkr work-order create -f failing-job.yaml --agent prod-1brokkr work-order status <work-order-2>The status after the Job ended:
work order <work-order-2>type: customowner: team-robincreated: 2026-11-14T16:18:25.790727+00:00status: FAILED at 2026-11-14T16:18:30.835460+00:00. agent "prod-1" ran it. Tries after the first: 0.result: failuremessage: Job default/backup-2026-11-14 ran and failed: BackoffLimitExceeded: Job has reached the specified backoff limitTo see the lines of its pods, run: brokkr work-order logs <work-order-2>The log lines of the failed Job are still there:
brokkr work-order logs <work-order-2>2026-11-14T16:18:27.852040+00:00 default/backup-2026-11-14-lnqdr/backup: backup: the bucket does not answerSend a work order to a label
Section titled “Send a work order to a label”A label reaches each agent that has the label and is registered with your generator. Here label-job.yaml is a Job like the one of step 1, and the agent prod-1 has the label env:prod. One of those agents claims the work order. An agent of another generator that has the same label does not get it.
brokkr work-order create -f label-job.yaml --label env:prodcreated work order <work-order-3> (type custom)targets: label env:prodAn agent that matches a target claims the work order on its next poll.To follow it, run: brokkr work-order status <work-order-3>brokkr work-order status <work-order-3>work order <work-order-3>type: customowner: team-robincreated: 2026-11-14T16:18:39.994911+00:00status: COMPLETED at 2026-11-14T16:18:50.042227+00:00. agent "prod-1" ran it. Tries after the first: 0.result: successmessage: Applied 1 resource(s). Job(s) default/report-2026-11-14 completed successfully.To see the lines of its pods, run: brokkr work-order logs <work-order-3>Refusals
Section titled “Refusals”The agent is not registered with your generator
Section titled “The agent is not registered with your generator”A generator sees only the agents that are registered with it. So your PAK cannot find an agent that is not registered by its name. The CLI cannot tell this from a name that no agent has, and the error says both:
brokkr work-order create -f migrate-job.yaml --agent prod-2error: invalid request: no agent that is registered with your generator has the name or id "prod-2". Either no agent has this name or id, or the agent is not registered with your generator. An admin registers an agent with a generator: brokkr register --agent prod-2 --generator <generator-id>. With the id of the agent in --agent, the broker says which of the two it is.With the id of the agent, the broker gives the reason:
brokkr work-order create -f migrate-job.yaml --agent <agent-id>error: agent <agent-id> is not registered with your generator, so the generator cannot send it a work order. The broker created nothing. An admin registers it: brokkr register --agent <agent-id> --generator <generator-id>In both cases the broker created nothing. Ask an admin to register the agent with your generator: each error gives the command. Then create the work order again.
The work order belongs to another owner
Section titled “The work order belongs to another owner”A generator reads and deletes only its own work orders. This is the answer when the generator team-sam asks for a work order of team-robin:
brokkr work-order status <work-order-1>error: work order <work-order-1> belongs to another owner. Use the PAK of the generator that owns it, or an admin PAK. To see which PAK you use, run: brokkr whoamiThe answer is the same for a work order that an admin created, also when it runs on your agent. Use the PAK of the generator that created the work order.
Delete a work order that waits
Section titled “Delete a work order that waits”A work order that no agent claims waits with no time limit. Here the agent prod-3 is registered with the generator, but it does not run. pending-job.yaml is the Job of step 1 with a new name:
brokkr work-order create -f pending-job.yaml --agent prod-3brokkr work-order listThe list shows the work order that waits:
ID TYPE STATUS OWNER AGE<work-order-4> custom PENDING team-robin 3sbrokkr work-order delete <work-order-4>deleted work order <work-order-4>You can also delete a work order that an agent has claimed. Brokkr does not stop the Job that the agent started: the Job runs to its end in the cluster. A work order that ended stays in the history and cannot be deleted:
brokkr work-order delete <work-order-1>error: work order <work-order-1> has ended (COMPLETED). A work order that ended stays in the log and cannot be deleted.Set the time limits
Section titled “Set the time limits”| Flag | Default | Meaning |
|---|---|---|
--claim-timeout <SECONDS> |
3600 | How long an agent can hold the work order. The agent watches the Job for this time, less 10% (and never less than 60 seconds less). A Job that still runs at the end of that window ends the work order with a failure, and the Job continues in the cluster. |
--max-retries <N> |
3 | How many times the broker tries again after a failure that can be tried again, for example an apply that failed. A Job that ran and failed is not tried again. |
--backoff <SECONDS> |
60 | The base of the wait before a new try. The first new try waits 2 × this value, and the wait doubles for each new try. |
For a Job that runs for 2 hours, give it a longer claim timeout:
brokkr work-order create -f long-job.yaml --agent prod-1 --claim-timeout 9000See Timing for each number.
What a work order does not do
Section titled “What a work order does not do”- It has no schedule. For a schedule, put a
CronJobin a stack. - It does not expire while it waits.
- It does not put a Job back that someone deleted from the cluster.
- It watches only a
batch/v1Job(and the build of abuildwork order) to its end. The agent applies any other kind and does not watch it, and it sends no pod logs for it.
Related
Section titled “Related”- Work Orders reference: the routes, who can call each one, and the timing.
- CLI reference: each flag of
brokkr work-order. - Using the Operator Console: the Work orders view shows the owner of each work order, and the pod logs and events of its job.
- Container Builds with Shipwright: the
buildwork type.