Scheduled Cleanup via External Cron
Delete expired records on a schedule by calling an action from an external cron service (GitHub Actions, cron-job.org, or a Cloudflare Worker Cron Trigger).
Config
typescript
actions: [{
name: 'cleanup_expired',
description: 'Delete records older than 30 days',
requireAuth: true,
guard: 'auth.role == "service"', // only callable by a service account
applyTableRules: false,
sql: [
{
type: 'DELETE',
table: 'sessions',
where: sql`created < datetime('now', '-30 days')`,
returning: ['*'],
},
{
type: 'DELETE',
table: 'request_log',
where: sql`created < datetime('now', '-7 days')`,
returning: ['*'],
},
],
}]Call from a cron
bash
# Create a service account with role "service" via PocketUI or direct INSERT
# Then call with that account's token:
curl -X POST https://your-app.example.com/api/v1/action/cleanup_expired \
-H 'Authorization: Bearer <service-account-token>'
# → [[{...expired sessions...}], [{...expired logs...}]]GitHub Actions example
yaml
# .github/workflows/cleanup.yml
name: Scheduled Cleanup
on:
schedule:
- cron: '0 3 * * *' # daily at 3am UTC
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- run: |
curl -X POST https://your-app.example.com/api/v1/action/cleanup_expired \
-H 'Authorization: Bearer ${{ secrets.SERVICE_TOKEN }}'