> ## Documentation Index
> Fetch the complete documentation index at: https://docs.strait.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Job Dependencies

> Ensuring execution order between jobs using dependencies.

Job dependencies allow you to define a relationship between two jobs, ensuring that one job only runs after another job has reached a specific state.

## Concepts

A **Job Dependency** consists of:

* **Job ID**: The job that is waiting for the dependency.
* **Depends On Job ID**: The job that must reach a certain state first.
* **Condition**: The state the dependency job must reach.

### Dependency Conditions

When creating a dependency, you can specify one of the following conditions:

* `completed` (Default): The dependency job must finish successfully.
* `failed`: The dependency job must fail.
* `any`: The dependency job must reach any terminal state (completed, failed, canceled, etc.).

## Use Cases

* **Sequential Processing**: Ensure Job B (e.g., "Generate Invoice") only runs after Job A (e.g., "Process Payment") completes successfully.
* **Error Handling**: Trigger Job C (e.g., "Notify Support") only if Job A fails.
* **Cleanup**: Run Job D (e.g., "Delete Temporary Files") regardless of whether Job A succeeded or failed.

## Managing Dependencies

<Note>
  Job dependencies are enabled by default.
</Note>

### Create a Dependency

To make Job B depend on Job A completing successfully:

```bash theme={null}
curl -X POST https://strait.dev/v1/jobs/{jobB_ID}/dependencies \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "depends_on_job_id": "{jobA_ID}",
    "condition": "completed"
  }'
```

### List Dependencies

To see all jobs that a specific job depends on:

```bash theme={null}
curl -H "Authorization: Bearer $API_KEY" \
  https://strait.dev/v1/jobs/{jobID}/dependencies
```

### Delete a Dependency

```bash theme={null}
curl -X DELETE https://strait.dev/v1/jobs/{jobID}/dependencies/{dependencyID} \
  -H "Authorization: Bearer $API_KEY"
```

## Behavior

When a job with dependencies is triggered:

1. Strait checks if all dependencies are met.
2. If dependencies are not met, the job run may enter a `waiting` state or be delayed until the conditions are satisfied.
3. Once all dependency conditions are met, the job is moved to the `queued` state for execution.

<Warning>
  Circular dependencies (e.g., Job A depends on Job B, and Job B depends on Job A) are not allowed and will result in a validation error.
</Warning>
