---
title: "Cancel a running execution and any associated Google Earth Engine tasks."
method: POST
path: "/api/v1/execution/{execution}/cancel"
---

# Cancel a running execution and any associated Google Earth Engine tasks.

`POST /api/v1/execution/{execution}/cancel`

**Authentication**: JWT token required
**Access**: Users can cancel their own executions, ADMIN+ users can cancel any
**Purpose**: Immediately stops execution processing, cleans up resources, and
cancels any associated Google Earth Engine tasks that may have been started.

**Path Parameters**:
- `execution`: The ID of the execution to cancel

**Request**: No request body required - this is a POST endpoint that triggers
cancellation

**Usage Examples**:
```bash
# Cancel your own execution
curl -X POST "https://api.trends.earth/api/v1/execution/abc123-def456/cancel"          -H "Authorization: Bearer your_jwt_token"

# Admin canceling any user's execution
curl -X POST "https://api.trends.earth/api/v1/execution/xyz789-uvw012/cancel"          -H "Authorization: Bearer admin_jwt_token"
```

**Success Response Schema**:
```json
{
  "data": {
    "execution": {
      "id": "abc123-def456",
      "script_id": "vegetation-analysis",
      "status": "CANCELLED",
      "params": {
        "region": "africa",
        "year_start": 2020,
        "year_end": 2023
      },
      "user_id": "user-789",
      "created_at": "2025-01-15T10:30:00Z",
      "updated_at": "2025-01-15T10:35:00Z",
      "start_time": "2025-01-15T10:31:00Z",
      "end_time": "2025-01-15T10:35:00Z",
      "progress": 100
    },
    "cancellation_details": {
      "execution_id": "abc123-def456",
      "previous_status": "RUNNING",
      "docker_service_stopped": true,
      "docker_container_stopped": false,
      "batch_jobs_terminated": [
        {
          "job_id": "aws-batch-job-id-123",
          "name": "extract",
          "previous_status": "RUNNING",
          "success": true
        }
      ],
      "gee_tasks_cancelled": [
        {
          "task_id": "6CIGR7EG2J45GJ2DN2J7X3WZ",
          "success": true,
          "error": null,
          "status": "CANCELLED"
        },
        {
          "task_id": "YBKKBHM2V63JYBVIPCCRY7A2",
          "success": true,
          "error": null,
          "status": "CANCELLED"
        }
      ],
      "errors": []
    }
  }
}
```

**Response Fields**:
- `execution`: The updated execution object with `CANCELLING` status
- `cancellation_details`: Dispatch metadata for background cancellation:
  - `execution_id`: ID of the execution being cancelled
  - `previous_status`: Status before cancellation request
  - `new_status`: Set to `CANCELLING`
  - `queued`: `true` when cancellation work was enqueued
  - `task_id`: Celery task ID handling cancellation
  - `errors`: Any immediate dispatch errors

 **Cancellation Process**:
 1. Request transitions execution to `CANCELLING`
 2. API returns `202 Accepted` immediately
 3. Background worker cancels compute resources and GEE tasks
 4. Background worker sets final status to `CANCELLED`

**Cancellable States**:
- `PENDING`: Execution queued, waiting to start
- `READY`: Execution initialized and starting
- `RUNNING`: Currently executing

**Non-Cancellable States**:
- `FINISHED`: Execution completed successfully
- `FAILED`: Execution already failed
- `CANCELLED`: Execution already cancelled
- `CANCELLING`: Cancellation already in progress

**Error Responses**:
- `400 Bad Request`: Execution is not in a cancellable state
  ```json
  {
    "status": 400,
    "detail": "Cannot cancel execution in FINISHED state"
  }
  ```
- `409 Conflict`: Cancellation is already in progress
  ```json
  {
    "status": 409,
    "detail": "Cancellation already in progress for this execution"
  }
  ```
- `401 Unauthorized`: JWT token required
- `403 Forbidden`: User can only cancel their own executions (unless admin)
  ```json
  {
    "status": 403,
    "detail": "You can only cancel your own executions"
  }
  ```
- `404 Not Found`: Execution does not exist
- `500 Internal Server Error`: Cancellation process failed

**Partial Cancellation**: The endpoint will attempt to cancel all associated
resources even if some steps fail. Check the `cancellation_details.errors` array
for any issues encountered during the process.

## Path parameters

- `execution` string, required

## Request body

- object

## Response `200`

Success

- object

## Other responses

- `400` — Bad Request
- `401` — Unauthorized
- `403` — Forbidden
- `404` — Not Found
- `500` — Internal Server Error

---

[API](https://skmtc.dev/trends/apis/trends-earth-api.md) · [All operations](https://skmtc.dev/trends/apis/trends-earth-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/trends/trends-earth-api/revisions/6bdbc0b84666/schema)
