# Scheduling

Herald is a job, not a server: run it once a day with cron, Docker or GitHub Actions. For the
long-running Telegram bot, see [Channels](channels.md#telegram-bot-for-subscribers).

## cron

On the machine where your keys or CLI login live, call Herald every hour and let it pick the
hour in your time zone:

```
10 * * * *  cd /path/to/herald && PATH=$HOME/.local/bin:/usr/bin:/bin uv run herald run --at 06:10 --days 1-5 >> data/cron.log 2>&1
```

`--at 06:10` runs the briefing only in the hour that starts at 06:10 in `config.json`'s
`timezone`, and `--days 1-5` only from Monday to Friday there (cron's weekday syntax: `0` or `7`
is Sunday, `*` every day, the default). Every other call exits at once with code 0 and logs one
line, `not due: runs at 06:10 <zone> ...`, so `data/cron.log` shows that cron is calling. Log
lines are stamped in the briefing's time zone, with its UTC offset. Cron reads its schedule in the machine's time zone, usually UTC on a server, and most
cron versions can't be told another one; this way neither that zone nor a daylight saving change
moves the briefing, and the weekdays are yours, not the server's. Keep the cron minute equal to
the `--at` minute so the run starts on time. Only when one of the two zones is offset by a half
hour (India, Iran, Newfoundland, central Australia) is the cron minute different: convert it, for
example with `date -d 'TZ="Asia/Kolkata" 06:10' +%M` on Linux.

Cron does not load your shell profile, so `PATH` must include `uv` (and `claude`/`codex` if you
use them). Set `schedule.skip_non_business_days` to `true` to skip B3 holidays.

**Start early enough.** A run takes a while: it fetches every source, embeds the stories and, with
an AI provider, waits for the model. With no AI, a few hundred sources take about 4 minutes on 2
vCPUs ([Getting started](getting-started.md#how-it-works)). Measure it instead of guessing: every
run report starts with `took 12m 05s`. Run `HERALD_AI_PROVIDER=none herald --dry-run` (free) and
one real run, take the longer, add a margin (a third, at least five minutes), and start that much
before the time you want to read it. Keep an eye on `took` in `data/cron.log` as you add
categories or languages.

## Docker

From a clone, with `compose.yaml` (it builds the image locally):

```bash
cp config.example.json config.json && cp .env.example .env   # the files must exist before mounting
docker compose build
docker compose run --rm herald init                 # onboarding inside the container
docker compose run --rm herald                      # one run; schedule with cron/systemd
docker compose run --rm herald run --dry-run --hours 12
```

`config.json` and `.env` are mounted read-write, so `init` and `categories` can save your choices.
History, briefings and the embedding model live in the `herald-data` volume. Tagged releases
also publish a ready image, `ghcr.io/felipebossolani/herald:<version>`, built by
`.github/workflows/release.yml` after the isolated tests pass. The Docker image works with
API-key providers only; `claude-code` and `codex` need the host, where the CLI is signed in.
Changes per version are in [`CHANGELOG.md`](../CHANGELOG.md).

With the published image instead of a clone, set it up as in
[Getting started](getting-started.md#run-the-docker-image) and schedule the same `docker run`
line (without `-it`) from cron, every hour with `run --at` as [above](#cron), for example:

```
10 * * * *  cd /path/to/herald && docker run --rm --user "$(id -u):$(id -g)" -v "$PWD/config.json:/app/config.json" -v "$PWD/.env:/app/.env" -v "$PWD/data:/app/data" ghcr.io/felipebossolani/herald:beta run --at 06:10 --days 1-5 >> data/cron.log 2>&1
```

## GitHub Actions

`.github/workflows/daily.yml` runs at 06:00 BRT on weekdays (the `cron` line is in UTC). To turn
it on in your fork:
- set the repository variable `HERALD_DAILY=true`;
- add your `config.json` as the `HERALD_CONFIG_JSON` secret;
- add each variable you filled in `.env` as a secret of the same name.

```bash
gh variable set HERALD_DAILY --body true
gh secret set HERALD_CONFIG_JSON < config.json
gh secret set ANTHROPIC_API_KEY    # prompts for the value
```

The workflow passes every variable of `.env.example` from the secret of the same name; a secret
you don't set arrives empty, which Herald treats as unset:

| Secrets | For |
|---|---|
| `HERALD_AI_PROVIDER`, `HERALD_SCORING_MODEL`, `HERALD_ENRICH_MODEL` | The AI provider (`anthropic` when unset) and its models |
| `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `OPENROUTER_API_KEY`, `OPENCODE_API_KEY`, `GEMINI_API_KEY` | The provider's key |
| `FRED_API_KEY`, `CONGRESS_API_KEY`, `SEC_USER_AGENT` | US data APIs and the contact the SEC asks for |
| `REDDIT_CLIENT_ID`, `REDDIT_CLIENT_SECRET` | The Reddit sources |
| `TELEGRAM_BOT_TOKEN`, `TELEGRAM_CHAT_ID` | Telegram |
| `SMTP_FROM`, `HERALD_UNSUBSCRIBE_URL`, `SMTP_HOST`, `SMTP_USER`, `SMTP_PASSWORD`, `RESEND_API_KEY` | Email |
| `SLACK_WEBHOOK_URL`, `DISCORD_WEBHOOK_URL`, `TEAMS_WEBHOOK_URL`, `GOOGLE_CHAT_WEBHOOK_URL` | Slack, Discord, Teams, Google Chat |
| `HERALD_WEBHOOK_URL`, `HERALD_WEBHOOK_SECRET`, `HERALD_WEBHOOK_TOKEN` | The webhook |
| `WHATSAPP_TOKEN`, `WHATSAPP_PHONE_NUMBER_ID` | WhatsApp |
| `MATRIX_TOKEN` | Matrix |
| `NTFY_TOPIC`, `NTFY_TOKEN`, `PUSHOVER_TOKEN`, `PUSHOVER_USER` | ntfy and Pushover |
| `GITHUB_TOKEN` | The GitHub source's rate limit: the workflow's own token, nothing to add |
| `HERALD_MCP_TOKEN` | Not used by the daily run |

It works with the API-key providers (`anthropic`, `openai`, `openrouter`, `opencode`,
`gemini`) and `none`; `claude-code` and `codex` need your signed-in CLI, and `ollama` a server
the runner can reach. Every channel works except email: subscriber data
(`data/subscribers.db`) is never cached on Actions, so send email from a host of your own. You
can also start it by hand: `gh workflow run daily.yml`, with `-f dry_run=true` to send nothing.
