Skip to content

Jobs

Some work takes longer than one tool call should: a large import, a scan, a long transfer. A service tool that starts such work answers at once with a jobId, and the work runs in the background as a job. The jobs tools follow it. They work for every service's jobs, are free to call, and only ever see the jobs of the organization you are acting in.

A job's states

StateMeans
queuedWaiting for a worker. The answer says where it stands in the queue.
runningA worker is on it. phase and progress say how far it has got.
waitingPaused until what it waits for arrives, such as a scan's verdict; it runs again on its own. phase says where it stopped.
succeededDone. result holds what it produced.
failedStopped with an error. failure holds the code and the reason.
canceledStopped because it was canceled.

The last three are final: a finished job never changes again. A finished job stays listed and readable for a time the platform sets, then is removed.

When a job is created, the tool that started it also says whether a worker is already running or still starting. A worker that is starting picks the job up as soon as it is ready. A jobs_status or jobs_list answer about a job that has not finished carries worker: "starting" while no worker is running yet, and no worker field once one is.

Reading a job: jobs_status

{ "jobId": "123e4567-e89b-12d3-a456-426614174000" }

The answer is the job as it stands: its state, kind and service, its progress, whether it can be canceled, and the times it was created, started and finished. A field that says nothing about the job's state is left out rather than sent empty:

  • phase, the step the job is on or what it waits for, appears only while the job has not finished and its kind has named a step.
  • heartbeatAt, when the worker last reported in, appears only while the job is running.
  • worker appears only as described above.
  • queuePosition appears only while it is queued, result only once it has succeeded, and failure only once it has failed.

cancelable is always there, and is false once the job has finished. A finished job's progress keeps its byte figures but not estimatedSecondsLeft, and is null when the time left was all the job reported.

Waiting for it

Add wait, a number of seconds, to hold the answer until the job finishes:

{ "jobId": "123e4567-e89b-12d3-a456-426614174000", "wait": 30 }

The answer comes as soon as the job finishes, or when the seconds run out, whichever is first. A wait longer than the platform's limit is cut to that limit, not refused: the answer is the job as it stands then. A job that has already finished, or a wait of 0, answers at once. If the answer comes back still queued, running or waiting, call again. Waiting is better than calling in a tight loop: one call with a wait does the work of many quick ones.

Listing jobs: jobs_list

Lists the organization's jobs: queued, running and waiting ones first, then recently finished ones, each newest first. Narrow it with state, kind (such as sample.wait), or both, and choose a pageSize. Each item has every field of jobs_status except result; read one job to see its result.

When the answer carries a nextCursor, pass it back as cursor, with the same state and kind, for the next page. A cursor works only with the filters it was issued for and only for your organization; anything else is refused, and you start again without one. nextCursor is null on the last page.

Canceling a job: jobs_cancel

{ "jobId": "123e4567-e89b-12d3-a456-426614174000" }
  • A queued or waiting job is canceled at once, and the answer is canceled.
  • A running job is asked to stop, and the answer is running: it stops at its next check-in and ends canceled. Follow it with jobs_status and a wait.
  • A finished job is left as it is, and the answer is its state. Canceling twice is harmless.
  • Some kinds of job cannot be canceled once created, such as a storage file's malware scan; canceling one that has not finished is refused with JOBS_NOT_CANCELABLE. The job's cancelable field says which kind it is while the job has not finished.

Anyone in the organization, person or agent, may cancel any of its jobs.

Canceling stops the job; what it had already done may stay. A service's help page says what a canceled job of its kinds leaves behind.

The Jobs page

People in your organization see the same jobs in the dashboard, on the Jobs page in the navigation. Every member sees every job of the organization, whichever service, agent or person started it, with its kind, service, state, phase, progress, the reason a failed job gives, and when it was created and finished. Active jobs are listed first.

  • The row of states along the top filters the list; All shows every state. The page's address keeps the filter and the page, so a view can be reloaded, bookmarked or shared with someone else in the organization.
  • Next page moves through a long list, and First page returns to the start.
  • Refresh reloads the list.
  • Cancel appears on a job that can be canceled and has not finished. It asks for confirmation first, then works as jobs_cancel does: a running job may show as running for a moment until it stops.

A job canceled from the page is canceled for the agent following it too: the agent sees it end canceled.

When a job is not found

JOBS_NOT_FOUND means no job of your organization has that id: it was mistyped, it belongs to another organization, or it finished long enough ago to have been removed.

Jobs