# Schedules

Schedules let you run HTTP requests on a recurring basis using cron expressions. Each schedule is a first-class resource that you can create, pause, resume, and delete independently.

### Creating a schedule

```bash
curl -X POST "https://api.zeplo.io/workspaces/WS_ID/schedules/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "sync-inventory",
    "queueId": "QUEUE_ID",
    "schedule": "0 */6 * * *",
    "requestTemplate": {
      "method": "POST",
      "url": "https://your-api.com/sync",
      "headers": {"Content-Type": "application/json"},
      "body": "{\"full_sync\": true}"
    }
  }'
```

This creates a schedule that runs every 6 hours.

### Cron syntax

Schedules use standard [cron syntax](https://crontab.guru/) with 5 fields:

```
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Sunday=0)
│ │ │ │ │
* * * * *
```

**Examples:**

| Expression | Description |
|-----------|-------------|
| `* * * * *` | Every minute |
| `0 * * * *` | Every hour |
| `0 9 * * 1-5` | 9 AM on weekdays |
| `0 0 1 * *` | Midnight on the 1st of each month |
| `*/15 * * * *` | Every 15 minutes |

### Schedule status

Schedules can be **active** or **paused**.

```bash
# Pause a schedule
curl -X PATCH "https://api.zeplo.io/workspaces/WS_ID/schedules/SCHEDULE_ID" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"status": "paused"}'

# Resume
curl -X PATCH "https://api.zeplo.io/workspaces/WS_ID/schedules/SCHEDULE_ID" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"status": "active"}'
```

### Execution tracking

Each time a schedule fires, a new request is created in the associated queue. You can see:

- **Next run** — When the schedule will fire next
- **Last run** — When it last fired
- **Request history** — All requests created by this schedule, with their statuses

### Retry behavior

Each scheduled execution inherits the request template's retry settings. If a scheduled request fails all its retries, the schedule continues — the next cron tick creates a fresh request.

### Deleting a schedule

```bash
curl -X DELETE "https://api.zeplo.io/workspaces/WS_ID/schedules/SCHEDULE_ID" \
  -H "Authorization: Bearer YOUR_TOKEN"
```

Deleting a schedule stops future executions. Requests already created by the schedule are not affected.
