Retention & Cleanup
@evlog/nuxthub automatically deletes old events based on your retention policy. No manual cleanup needed.
Configuration
Set the retention period in your nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@nuxthub/core', '@evlog/nuxthub'],
evlog: {
retention: '7d', // default
},
})
Retention Format
The retention value is a number followed by a unit:
| Unit | Description | Example |
|---|---|---|
d | Days | 7d = 7 days |
h | Hours | 24h = 24 hours |
m | Minutes | 60m = 60 minutes |
How Cleanup Works
The module registers a Nitro scheduled task (evlog:cleanup) that runs on a cron schedule derived from your retention value. The cron frequency is set to roughly half the retention period:
| Retention | Cron Schedule | Description |
|---|---|---|
60m | */30 * * * * | Every 30 minutes |
24h | 0 */12 * * * | Every 12 hours |
7d | 0 3 * * * | Daily at 3:00 AM |
30d | 0 3 * * * | Daily at 3:00 AM |
The cleanup task deletes all rows in evlog_events where created_at is older than the retention period.
Manual Cleanup
You can trigger cleanup manually via the API endpoint:
curl https://your-app.com/api/_cron/evlog-cleanup
Cron Secret Protection
If the CRON_SECRET environment variable is set, the endpoint requires a Bearer token:
curl -H "Authorization: Bearer your-secret" \
https://your-app.com/api/_cron/evlog-cleanup
This is recommended for production deployments to prevent unauthorized cleanup triggers.
Vercel Cron
When installing the module with nuxi module add, you'll be prompted to create a vercel.json with the appropriate cron schedule:
{
"crons": [
{
"path": "/api/_cron/evlog-cleanup",
"schedule": "0 3 * * *"
}
]
}
On Vercel, the CRON_SECRET environment variable is automatically set and validated.
Cloudflare & Other Platforms
On Cloudflare Workers and other platforms, the Nitro scheduled task handles cleanup automatically without any additional cron configuration. The task is registered with experimental.tasks enabled in the Nitro config.