Skip to main content

Endpoint

Authentication

This endpoint requires API key authentication via the Authorization header:

Path Parameters

string
required
The unique identifier of the task to cancel

Requirements

  • Task must have status Starting
  • Tasks that are already Processing, Succeeded, Failed, or Cancelled cannot be cancelled

Response

On success, returns a plain text response:

Status Codes

  • 200: Task cancelled successfully
  • 400: Bad request (task cannot be cancelled due to invalid status)
  • 404: Task not found or expired
  • 500: Internal server error

Behavior

Depending on the task state:
  • For new tasks: Status will be updated to Cancelled and processing will never begin
  • For updating tasks: Task will revert to its previous state before the update was requested

Examples

Use Cases

  1. Accidental Submissions: Cancel tasks that were created by mistake
  2. Configuration Errors: Cancel and recreate tasks with corrected settings
  3. Queue Management: Cancel low-priority tasks during high-load periods
  4. Testing: Cancel test tasks that are no longer needed

Timing Window

Tasks can only be cancelled while they’re in the Starting state, which is typically:
  • Right after task creation
  • Before worker processes pick up the task
  • During the queue waiting period
Once a task moves to Processing state, it cannot be cancelled and must complete or fail naturally.

After Cancellation

Once a task is cancelled:
  1. Status changes to Cancelled
  2. Message is updated to “Task cancelled”
  3. Task will never begin processing
  4. Task can be deleted to free up resources
  5. Task cannot be restarted - you must create a new task instead

Error Messages

The task ID doesn’t exist, has expired, or you don’t have access to it
The task is not in Starting state. Common reasons:
  • Task is already Processing
  • Task has Succeeded or Failed
  • Task was already Cancelled

Best Practices

  1. Check Status First: Verify the task is in Starting state before attempting to cancel
  2. Quick Action: Cancel as soon as you realize the task is not needed, as tasks may move to Processing quickly
  3. Create New Tasks: After cancelling, create a new task with correct settings rather than trying to uncancelled
  4. Clean Up: Consider deleting cancelled tasks to keep your task list clean

Advanced Example: Cancel and Recreate

  • Delete Task - Permanently delete a Succeeded, Failed, or Cancelled task
  • Get Task - Check task status before cancelling
  • Create Task - Create a new task to replace the cancelled one