Scheduled Cron Tasks
Schedule recurring background tasks to run automatically on your isolated PocketBase instances.
Standard 5-Field Cron Expressions
| Expression | Description |
|---|---|
*/5 * * * * | Every 5 minutes |
0 * * * * | Every hour at minute 0 |
0 0 * * * | Daily at midnight (00:00 UTC) |
0 0 * * 0 | Weekly on Sunday at midnight |
0 0 1 * * | Monthly on the 1st day at midnight |
Example Worker Code
// PocketBase Goja runtime worker$app.logger().info("[Cron] Starting nightly maintenance...");
// Find and delete expired tokensconst expiredTokens = $app.findRecordsByFilter( "_otps", "created < {:cutoff}", "-created", 100, 0, { cutoff: new Date(Date.now() - 24 * 3600 * 1000).toISOString() });
for (const rec of expiredTokens) { $app.delete(rec);}
$app.logger().info("[Cron] Purged " + expiredTokens.length + " expired tokens.");