Job
c.Job calls the API's Job group. Operations related to the job queue.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
List(ctx, params) | *Response[ListJobsResponse] | job:read | List jobs. |
Get(ctx, id) | *Response[JobDetailResponse] | job:read | Get job detail. |
Delete(ctx, id) | error | job:write | Delete a job. |
Retry(ctx, input) | *Response[CreateJobResponse] | job:write | Retry a job. |
List
func (s *JobService) List(
ctx context.Context,
params JobListParams,
) (*Response[ListJobsResponse], error)
List jobs.
Retrieve jobs, optionally filtered by status. A token with a target scope gets only the jobs whose target is in its scope, and the counts include only those jobs.
It sends GET /api/job, and needs the permission job:read.
The examples of the method's definition:
List jobs, go run job.go list:
resp, err := c.Job.List(ctx, client.JobListParams{})
List jobs, with --status completed --limit 3, go run job.go list-2:
resp, err := c.Job.List(ctx, client.JobListParams{
Limit: 3,
Status: types.JobStatus("completed"),
})
Get
func (s *JobService) Get(
ctx context.Context,
id string,
) (*Response[JobDetailResponse], error)
Get job detail.
Retrieve details of a specific job by its ID. A job whose target is outside the target scope of the token is not found.
It sends GET /api/job/{id}, and needs the permission job:read.
The examples of the method's definition:
Get job detail, go run job.go get:
resp, err := c.Job.Get(ctx, "550e8400-e29b-41d4-a716-446655440000")
Delete
func (s *JobService) Delete(
ctx context.Context,
id string,
) error
Delete a job.
Delete a specific job by its ID. A job whose target is outside the target scope of the token is not found.
It sends DELETE /api/job/{id}, and needs the permission job:write.
The examples of the method's definition:
Delete a job, go run job.go delete:
err := c.Job.Delete(ctx, "550e8400-e29b-41d4-a716-446655440000")
Retry
func (s *JobService) Retry(
ctx context.Context,
input JobRetryInput,
) (*Response[CreateJobResponse], error)
Retry a job.
Create a new job using the same operation data as an existing job. The original job is preserved. Returns the new job ID.
It sends POST /api/job/{id}/retry, and needs the permission job:write.
The examples of the method's definition:
Retry a job, go run job.go retry:
resp, err := c.Job.Retry(ctx, client.JobRetryInput{ID: "550e8400-e29b-41d4-a716-446655440000"})
Types
The fields of each type are the properties of its schema in the API's spec.
AgentJobStatus
The status of a job on one host. The controller records submitted and retried; an agent records acknowledged, started, completed, failed or skipped; and timeout is a host whose agent did not answer in time.
A string, one of submitted, acknowledged, started, completed,
failed, skipped, retried, timeout.
CreateJobResponse
| Field | Type | Description |
|---|---|---|
JobID | string | Unique identifier for the created job. |
Revision | int64 | The KV revision number. |
Status | JobStatus | The status of a job, which the controller computes from what each agent did: submitted, processing, completed, failed, partial_failure (completed on some agents and failed on others) or skipped (each agent skipped it). |
Timestamp | string | Creation timestamp. |
JobDetailResponse
| Field | Type | Description |
|---|---|---|
AgentStates | []JobDetailResponseAgentStatesItem | How far each agent got, by hostname. |
Chain | []string | The calls of other behaviors that the method made on each host, one line for each host, such as web-01: netplan update (changed) → managedfile update (changed). |
Changed | bool | Whether the operation modified system state. Null for pending/failed jobs; true/false for completed jobs. |
Created | string | Creation timestamp. |
Error | string | Error message if failed. |
Hostname | string | Agent hostname that processed the job. |
ID | string | Unique identifier of the job. |
Operation | JobDetailResponseOperation | What the job asked for, with each secret masked. |
Responses | []JobDetailResponseResponsesItem | What each agent answered, by hostname. |
Result | any | The result data if completed. |
Status | JobStatus | The status of a job, which the controller computes from what each agent did: submitted, processing, completed, failed, partial_failure (completed on some agents and failed on others) or skipped (each agent skipped it). |
Target | string | The target the request gave: _any, _all, a hostname, or a label such as group:web.dev. A job stored before targets were kept has the host that answered. |
Timeline | []JobDetailResponseTimelineItem | Chronological sequence of job lifecycle events. |
UpdatedAt | string | Last update timestamp. |
JobDetailResponseAgentStatesItem
| Field | Type | Description |
|---|---|---|
Duration | string | |
Error | string | |
Hostname | string | |
Status | AgentJobStatus | The status of a job on one host. The controller records submitted and retried; an agent records acknowledged, started, completed, failed or skipped; and timeout is a host whose agent did not answer in time. |
JobDetailResponseOperation
What the job asked for, with each secret masked.
| Field | Type | Description |
|---|---|---|
Data | any | The data of the operation, with each secret masked. |
Type | string | The operation, such as node.hostname.get. |
JobDetailResponseResponsesItem
| Field | Type | Description |
|---|---|---|
Changed | bool | |
Data | any | Agent result data. |
Error | string | |
Hostname | string | |
Status | AgentJobStatus | The status of a job on one host. The controller records submitted and retried; an agent records acknowledged, started, completed, failed or skipped; and timeout is a host whose agent did not answer in time. |
Steps | []Step | The calls of other behaviors that the method made on the host, also when one failed. |
JobDetailResponseTimelineItem
| Field | Type | Description |
|---|---|---|
Error | string | Error details if applicable. |
Event | AgentJobStatus | The status of a job on one host. The controller records submitted and retried; an agent records acknowledged, started, completed, failed or skipped; and timeout is a host whose agent did not answer in time. |
Hostname | string | Agent or source that generated the event. |
Message | string | Human-readable description of the event. |
Timestamp | string | ISO 8601 timestamp of the event. |
JobRetryInput
| Field | Type | Description |
|---|---|---|
ID | string | The id of the path. UUID of the job to retry. |
TargetHostname | string | The target of the retried job: _any, _all, a hostname, or a label such as group:web.dev. |
JobStatus
The status of a job, which the controller computes from what each agent did: submitted, processing, completed, failed, partial_failure (completed on some agents and failed on others) or skipped (each agent skipped it).
A string, one of submitted, processing, completed, failed,
partial_failure, skipped.
ListJobsResponse
| Field | Type | Description |
|---|---|---|
Items | []JobDetailResponse | |
StatusCounts | map[string]int | Count of all jobs by status. Derived from key names during the listing pass, with no extra reads. |
TotalItems | int | Total number of jobs matching the filter. |
Step
| Field | Type | Description |
|---|---|---|
Behavior | string | |
Changed | bool | |
DurationMS | int64 | |
Error | string | |
Method | string | |
Steps | []Step |
Example
examples/sdk/client/job.go
runs each example of this page. With no argument, it lists them.