Use this feature when a job chain is stuck or when a large number of jobs was scheduled by mistake. A job chain is a set of processing jobs that depend on each other. CG Cloud Processing Services runs job chains outside Salesforce. A job chain worker picks up the jobs and runs them in order. Aborting a job chain ends the job chain worker.
Aborting takes two steps. First, get the job identifier of the running job chain worker. Then, delete the job by its identifier.
Both steps use the global <namespace>.OffPlatformCallout class. Pass the sales org to the constructor. The sales org is required. For more information about the effect of the sales org, see Abort Behavior.
Step 1. Get the Job Identifier
This request returns the job identifier of the running job chain worker.
Resource
JOBCHAINWORKER_ABORT_GET_JOB_ID
Available version
68.0
Apex Request Example
String endpointName = 'JOBCHAINWORKER_ABORT_GET_JOB_ID'; String salesOrg = '9999'; <namespace>.OffPlatformCallout request = new <namespace>.OffPlatformCallout(endpointName, salesOrg); // This request has no path variables and no request body. <namespace>.OffplatformCalloutResponse response = request.execute( <namespace>.TransactionHandler.getTransactionIdentifier(), null, null ); if (response.status != 200) { // A 404 status means that no job chain worker can be aborted. return; } Map<String, Object> body = (Map<String, Object>) JSON.deserializeUntyped(response.result); String k8sJobId = (String) body.get('k8sJobId');
The response body contains the k8sJobId, jobState, and launchId fields. Use the value of k8sJobId in step 2.
Step 2. Abort the Job
This request deletes the job and ends the job chain worker.
The resource path contains the :k8sjobid variable. To set its value, pass a map to execute(). The map key must be k8sjobid, with the same spelling and case. If the key does not match, the variable is not replaced and the request fails.
Resource
JOBCHAINWORKER_ABORT_DELETE_JOB
Available version
68.0
Apex Request Example
String endpointName = 'JOBCHAINWORKER_ABORT_DELETE_JOB'; String salesOrg = '9999'; String k8sJobId = 'JOB_ID_FROM_STEP_1'; <namespace>.OffPlatformCallout request = new <namespace>.OffPlatformCallout(endpointName, salesOrg); <namespace>.OffplatformCalloutResponse response = request.execute( <namespace>.TransactionHandler.getTransactionIdentifier(), new Map<String, String>{ 'k8sjobid' => k8sJobId }, null ); if (response.status != 200) { // A 404 status means that the job no longer exists. return; }
The response body contains the message, k8sJobId, and abortedAt fields.
The response object has the following properties.
- status is an Integer that holds the HTTP status code.
- result is a String that holds the response body.
- message is a String that holds the status message.