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

# Scheduled Jobs

> Run background tasks on a schedule.

Backdrift supports scheduled jobs for recurring tasks like sending reports, cleaning up old data, or syncing with external systems.

## Defining Jobs

Describe what should happen and when:

```
"Run a nightly job to archive completed tasks older than 30 days."
```

```
"Every Monday at 9 AM, send a weekly summary email to all users."
```

```
"Every hour, check for expiring subscriptions and send reminders."
```

## Schedule Formats

Backdrift understands natural language schedules:

| Description             | Cron Expression    |
| ----------------------- | ------------------ |
| "Every day at midnight" | `0 0 * * *`        |
| "Every hour"            | `0 * * * *`        |
| "Every Monday at 9 AM"  | `0 9 * * MON`      |
| "First of every month"  | `0 0 1 * *`        |
| "Every 15 minutes"      | `*/15 * * * *`     |
| "Weekdays at 6 PM"      | `0 18 * * MON-FRI` |

## How It Works

```mermaid theme={null}
graph LR
    A[Scheduler] --> B[Job Queue]
    B --> C[Job Handler]
    C --> D[Your Logic]
    D --> E[Done]
```

1. **Scheduler** triggers on the defined schedule
2. **Job Queue** ensures reliable delivery
3. **Job Handler** executes your logic
4. **Retries** if the job fails

## Job Features

<CardGroup cols={2}>
  <Card title="Reliable Execution" icon="check">
    Jobs run exactly once, with automatic retries on failure.
  </Card>

  <Card title="Error Handling" icon="triangle-exclamation">
    Failed jobs go to a dead-letter queue for debugging.
  </Card>

  <Card title="Logging" icon="file-lines">
    Full execution logs available in the Admin Dashboard.
  </Card>

  <Card title="Manual Trigger" icon="play">
    Run jobs on-demand from the Admin Dashboard.
  </Card>
</CardGroup>

## Example Jobs

### Data Cleanup

```
"Every night at 2 AM, delete sessions older than 7 days."
```

### Report Generation

```
"Every Monday at 6 AM, generate a weekly activity report
and email it to organization admins."
```

### External Sync

```
"Every 5 minutes, sync new orders with the inventory system."
```

### Reminders

```
"Every day at 8 AM, find tasks due today and send
reminder emails to assignees."
```

## Monitoring Jobs

In the **Admin Dashboard** → **Jobs** tab:

* View all scheduled jobs
* See last run status and timing
* Expand to see execution history
* Click **Run Now** to trigger manually
* View logs for each execution

## Dead Letter Queue

Failed jobs (after retries) go to a Dead Letter Queue:

* Jobs are retained for 14 days
* View failure reason and stack trace
* Retry or delete from the queue
* Alert on DLQ depth

## Best Practices

<AccordionGroup>
  <Accordion title="Idempotency">
    Jobs might run twice (rare, but possible). Design for idempotency:

    ❌ "Send email to users"
    ✅ "Send email to users who haven't received it today"
  </Accordion>

  <Accordion title="Timeouts">
    Jobs have a 15-minute timeout by default. For longer tasks, use [Durable Workflows](/capabilities/durable-workflows).
  </Accordion>

  <Accordion title="Error Handling">
    Jobs retry 3 times with exponential backoff. After that, they go to the DLQ.
  </Accordion>

  <Accordion title="Concurrency">
    Jobs run in parallel by default. If you need serial execution, specify it:

    "Run sequentially to avoid race conditions."
  </Accordion>
</AccordionGroup>

## Event-Driven Jobs

Jobs can also trigger on events, not just schedules:

```
"When a task is marked complete, notify the project owner."
```

```
"When a user signs up, send a welcome email."
```

These create event-driven triggers instead of scheduled ones.

<Card title="Durable Workflows" icon="infinity" href="/capabilities/durable-workflows">
  For long-running processes that need to pause and resume.
</Card>
