Cancel an Asynchronous Job

post

/r-scripts/v2/jobs/{jobId}/cancel

Cancel a running asynchronous job specified by *jobId* while preserving the job comments if any.

Request

Path Parameters

There's no request body for this operation.

Back to Top

Response

Supported Media Types

200 Response

Job is cancelled.
Body ()
Root Schema : JSONObject
Type: object
Show Source

400 Response

Job is not running or is a preload job.
Body ()
Root Schema : PyScriptExecutionException
Type: object
Show Source

401 Response

When the user doesn't have privileges to perform the action.
Body ()
Root Schema : UnauthorizedException
Type: object
Show Source

404 Response

Resource not found, when the job id is not found.
Body ()
Root Schema : AbstractOmlException
Type: object
Show Source

500 Response

Problem connecting to Broker, finding the job id or other unexpected error.
Body ()
Root Schema : ComputeContainerException
Type: object
Show Source
Back to Top

Examples

An asynchronous job runs in the background after it is submitted. If you need to stop a job before it finishes, send a cancellation request using the job ID returned in the Location header. You can then check the job status and retrieve the result to confirm that the job was cancelled. The following steps show this process.

Cancel a running asynchronous job by following these steps:

  1. Submit the job with asyncFlag set to true.
  2. Use the job ID returned in the Location header to send a cancellation request.
  3. Check the job status.
  4. Fetch the job result.

Step 1: Submit an asynchronous job

This example submits the sleep_33mins function as an asynchronous job.

curl -i -k -X POST \
    --header "Authorization: Bearer ${token}" \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    -d '{
        "comments": "long running job that sleeps 33mins",
        "asyncFlag": true
    }' \
    "<oml-cloud-service-location-url>/oml/api/r-scripts/v2/do-eval/sleep_33mins"

The response includes HTTP status 201 Created and a Location header containing the job ID.

HTTP/2 201 Created
server: nginx/1.14.1
date: Thu, 23 Jul 2026 15:46:25 GMT
content-length: 0
strict-transport-security: max-age=31536000;includeSubDomains
x-content-type-options: nosniff
set-cookie: JSESSIONID=node0a2ukgrg0zetn34usmt4qdu7p16.node0; Path=/oml; Secure; HttpOnly
expires: Thu, 01 Jan 1970 00:00:00 GMT
location: https://<oml-cloud-service-location-url>/oml/api/r-scripts/v2/jobs/<job_id>

Step 2: Cancel the job

Wait for 10 seconds, then send a POST request to cancel the endpoint. The request has no body.

sleep 10
curl -i -k -X POST \
    --header "Authorization: Bearer ${token}" \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    "<oml-cloud-service-location-url>/oml/api/r-scripts/v2/jobs/<job_id>/cancel"

The response indicates that the job was cancelled successfully. {"result":"job cancelled successfully"}

Step 3: Check the job status

Call the job status endpoint with the job ID.

curl -i -k -X GET \
    --header "Authorization: Bearer ${token}" \
    --header 'Accept: application/json' \
    "<oml-cloud-service-location-url>/oml/api/r-scripts/v2/jobs/<job_id>"

The response redirects to the job result URL with HTTP status 302 Found.

HTTP/2 302 Found
server: nginx/1.14.1
date: Thu, 23 Jul 2026 15:50:43 GMT
content-length: 0
strict-transport-security: max-age=31536000;includeSubDomains
x-content-type-options: nosniff
content-location: https://<oml-cloud-service-location-url>/oml/api/r-scripts/v2/jobs/<job_id>/result

Step 4: Fetch the job result

Send a request to the URL in the Content-Location header.

curl -i -k -X GET \
    --header "Authorization: Bearer ${token}" \
    --header 'Accept: application/json' \
    "<oml-cloud-service-location-url>/oml/api/r-scripts/v2/jobs/<job_id>/result"

The result has HTTP status 200 OK and reports the job status as CANCLLED.

{
    "result": null,
    "comments": "long running job that sleeps 33mins",
    "status": "CANCELLED"
}
Back to Top