Skip to main content

Job

c.Job calls the API's Job group. Operations related to the job queue.

Methods​

MethodReturnsPermissionDescription
List(ctx, params)*Response[ListJobsResponse]job:readList jobs.
Get(ctx, id)*Response[JobDetailResponse]job:readGet job detail.
Delete(ctx, id)errorjob:writeDelete a job.
Retry(ctx, input)*Response[CreateJobResponse]job:writeRetry 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​

FieldTypeDescription
JobIDstringUnique identifier for the created job.
Revisionint64The KV revision number.
StatusJobStatusThe 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).
TimestampstringCreation timestamp.

JobDetailResponse​

FieldTypeDescription
AgentStates[]JobDetailResponseAgentStatesItemHow far each agent got, by hostname.
Chain[]stringThe 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).
ChangedboolWhether the operation modified system state. Null for pending/failed jobs; true/false for completed jobs.
CreatedstringCreation timestamp.
ErrorstringError message if failed.
HostnamestringAgent hostname that processed the job.
IDstringUnique identifier of the job.
OperationJobDetailResponseOperationWhat the job asked for, with each secret masked.
Responses[]JobDetailResponseResponsesItemWhat each agent answered, by hostname.
ResultanyThe result data if completed.
StatusJobStatusThe 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).
TargetstringThe 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[]JobDetailResponseTimelineItemChronological sequence of job lifecycle events.
UpdatedAtstringLast update timestamp.

JobDetailResponseAgentStatesItem​

FieldTypeDescription
Durationstring
Errorstring
Hostnamestring
StatusAgentJobStatusThe 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.

FieldTypeDescription
DataanyThe data of the operation, with each secret masked.
TypestringThe operation, such as node.hostname.get.

JobDetailResponseResponsesItem​

FieldTypeDescription
Changedbool
DataanyAgent result data.
Errorstring
Hostnamestring
StatusAgentJobStatusThe 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[]StepThe calls of other behaviors that the method made on the host, also when one failed.

JobDetailResponseTimelineItem​

FieldTypeDescription
ErrorstringError details if applicable.
EventAgentJobStatusThe 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.
HostnamestringAgent or source that generated the event.
MessagestringHuman-readable description of the event.
TimestampstringISO 8601 timestamp of the event.

JobRetryInput​

FieldTypeDescription
IDstringThe id of the path. UUID of the job to retry.
TargetHostnamestringThe 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​

FieldTypeDescription
Items[]JobDetailResponse
StatusCountsmap[string]intCount of all jobs by status. Derived from key names during the listing pass, with no extra reads.
TotalItemsintTotal number of jobs matching the filter.

Step​

FieldTypeDescription
Behaviorstring
Changedbool
DurationMSint64
Errorstring
Methodstring
Steps[]Step

Example​

examples/sdk/client/job.go runs each example of this page. With no argument, it lists them.