cf-node-client
momo auto_awesome BUY CLAUDE KIT WITH 20% OFF coffee BUY ME COFFEE

Class: Jobs

Jobs(endPointopt, optionsopt)

Jobs — background job and task management for Cloud Foundry. **Terminology:** - **v2 Jobs** (`/v2/jobs`): background operations tracked by the CC. - **v3 Tasks** (`/v3/tasks`): one-off processes run within an app context. - **v3 Jobs** (`/v3/jobs`): async operation polling for long-running CC operations (e.g. org/space delete, service instance provisioning). These are returned in `Location` headers with 202 Accepted responses. The getJobs/getJob/add/cancel methods manage **v2 Jobs** and **v3 Tasks**. The getV3Job/pollJob methods manage **v3 async operation Jobs**.

Constructor

new Jobs(endPointopt, optionsopt)

Parameters:
Name Type Attributes Default Description
endPoint String <optional>
Cloud Controller API endpoint URL
options Object <optional>
{} Options (same as CloudControllerBase)
Source:

Methods

add(appGuid, taskOptions) → {Promise}

Create a Task (v3 only). NOTE: Tasks are a v3-only concept. v2 does not support task creation.
Parameters:
Name Type Description
appGuid String Application unique identifier
taskOptions Object Task creation options
Source:
Throws:
If using v2 API (tasks not supported)
Type
Error
Returns:
Resolves with JSON task object
Type
Promise

cancel(guid) → {Promise}

Cancel a Task (v3) or delete a Job (v2).
Parameters:
Name Type Description
guid String Task/Job unique identifier
Source:
Returns:
Resolves when task is cancelled / job is deleted
Type
Promise

getJob(guid) → {Promise}

Get a single Job (v2) or Task (v3) by GUID. NOTE: For v3 async operation Jobs (from 202 Location headers), use getV3Job().
Parameters:
Name Type Description
guid String Job/Task unique identifier
Source:
Returns:
Resolves with JSON job/task object
Type
Promise

getJobs(filteropt) → {Promise}

Get Jobs list (v2) or Tasks list (v3).
Parameters:
Name Type Attributes Description
filter Object <optional>
Query-string filter options
Source:
Returns:
Resolves with JSON jobs/tasks list
Type
Promise

getV3Job(jobGuid) → {Promise}

Get a v3 async operation Job by GUID. v3 Jobs track background CC operations (org delete, service provisioning, etc.). They are separate from v3 Tasks (which run inside app containers).
Parameters:
Name Type Description
jobGuid String Job GUID (from Location header of 202 responses)
Source:
Returns:
Resolves with job object { guid, state, operation, errors, ... } state: "PROCESSING" | "POLLING" | "COMPLETE" | "FAILED"
Type
Promise

pollJob(jobGuid, optionsopt) → {Promise}

Poll a v3 async operation Job until it completes or fails. Repeatedly queries GET /v3/jobs/:guid until state is COMPLETE or FAILED.
Parameters:
Name Type Attributes Description
jobGuid String Job GUID
options Object <optional>
Polling options
Properties
Name Type Attributes Default Description
interval Number <optional>
2000 Poll interval in ms (default 2s)
timeout Number <optional>
300000 Max wait time in ms (default 5min)
Source:
Returns:
Resolves with completed job object, rejects on FAILED or timeout
Type
Promise