Files
wehub-resource-sync 3a28426bf4
Lint and Format Check / lint-and-format (push) Failing after 0s
Check Migrations / Check for duplicate migration numbers (push) Failing after 1s
CI Pre-merge Check / CI Pre-merge Check (push) Failing after 2m17s
chore: import upstream snapshot with attribution
2026-07-13 12:23:40 +08:00

44 lines
1.6 KiB
Plaintext

---
title: "Schedules: cron-triggered functions"
description: "Run a function on a cron schedule using pg_cron"
---
Schedules invoke functions on a recurring cron expression. [pg_cron](https://github.com/citusdata/pg_cron) fires an HTTP request to the function URL at each tick and logs the result.
## Concepts
A schedule is a cron expression, a target URL, and headers. On creation, `${{secrets.KEY}}` placeholders in headers are resolved and encrypted with `pgcrypto`. At each tick, `execute_job()` decrypts headers, calls the function, and writes status and duration to `schedules.job_logs`.
## Usage
Standard 5-field cron (no seconds). Reference secrets in headers instead of hardcoding keys.
```text
*/5 * * * * every 5 minutes
0 * * * * every hour
0 0 * * * daily at midnight
0 9 * * 1 every Monday at 9am
0 0 1 * * first of every month
```
Create via dashboard or SQL:
```sql
select schedules.create_job(
name => 'daily-cleanup',
schedule => '0 0 * * *',
url => 'https://myapp.functions.insforge.app/cleanup',
headers => jsonb_build_object('Authorization', 'Bearer ${{secrets.CRON_TOKEN}}')
);
```
## Limits
Minimum interval is 1 minute (pg_cron). Failed runs are logged but not retried, so the function must be idempotent. Deleting a referenced secret breaks every job using it until you update or disable the schedule.
## More resources
- [pg_cron docs](https://github.com/citusdata/pg_cron) for cron syntax.
- [Functions overview](/core-concepts/functions/overview) for the runtime.
- [crontab.guru](https://crontab.guru) to check an expression.