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

# Schedule time-window alerts with cron

> Use a cron schedule in the alert editor or API to check for missing logs during business hours and skip quiet periods in your local time zone.

> [!NOTE]
>
> **Applies to:**
>
> * Plan - Any plan can edit existing alerts. Creating alerts requires Starter with on-demand usage enabled, Pro, or Enterprise.
> * Deployment - Any
> *
> * Use case - Check for missing logs during business hours.

## Summary

Use a cron schedule to restrict a time-window alert to business hours. This is useful when the alert checks for missing logs and you expect little or no traffic overnight.

## What is happening

Each scheduled check looks back over the configured window. If traffic starts at 8:30 AM and the window is 30 minutes, schedule the first check for 9:00 AM so the entire window falls within business hours.

## Fix or suggestion

### Use the alert editor

1. Open the automation in the alert editor.
2. Open **Advanced settings**.
3. Under **Evaluation schedule**, choose **Cron**.
4. Enter a five-field numeric cron expression and set the IANA timezone.
5. Save the automation.

### Use the API

Create an alert with `POST /v1/project_automation`. To change an existing schedule, send `PATCH /v1/project_automation/{project_automation_id}` with the full existing `config` object and the new `config.window.schedule`.

This example checks every five minutes from 9:00 AM through 4:55 PM Pacific time, Monday through Friday. It sends a webhook when the previous 30 minutes contain zero logs. Replace both occurrences of `PROJECT_ID` with your project ID and `WEBHOOK_URL` with your webhook endpoint.

```json theme={null}
{
  "project_id": "PROJECT_ID",
  "name": "Logging stopped (business hours)",
  "config": {
    "event_type": "windowed",
    "threshold": {
      "calculation": {
        "type": "btql",
        "btql_query": "SELECT COUNT(*) AS log_count FROM project_logs('PROJECT_ID')",
        "output": { "type": "scalar", "value_column": "log_count" }
      },
      "policy": {
        "condition": { "type": "threshold", "operator": "eq", "threshold": 0 },
        "pending_seconds": 0,
        "no_data_behavior": "alert",
        "notify_on_recovery": false
      }
    },
    "actions": [{ "type": "webhook", "url": "WEBHOOK_URL" }],
    "window": {
      "window_seconds": 1800,
      "schedule": {
        "type": "cron",
        "cron_expression": "*/5 9-16 * * 1-5",
        "timezone": "America/Los_Angeles"
      },
      "evaluation_delay_seconds": 0
    }
  }
}
```

### Cron syntax constraints

* Use five numeric fields only.
* Use numeric weekdays (for example `1-5` for Monday–Friday). Named weekdays like `MON-FRI` are not accepted.
* `timezone` must be an IANA name or omitted to use UTC.

## How to confirm it worked

In a test project, pause logging for a full window during scheduled hours and confirm your webhook receives a firing notification. In the payload, check that `details.time_start` and `details.time_end` cover the expected 30-minute window.

## Notes

See the [Create project automation API reference](https://docs.braintrust.dev/api-reference/projectautomations/create-project-automation.md) for the full `WindowedAutomationConfig` schema and all schedule fields.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.