Skip to content

Scheduled Cron Tasks

Schedule recurring background tasks to run automatically on your isolated PocketBase instances.


Standard 5-Field Cron Expressions

ExpressionDescription
*/5 * * * *Every 5 minutes
0 * * * *Every hour at minute 0
0 0 * * *Daily at midnight (00:00 UTC)
0 0 * * 0Weekly 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 tokens
const 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.");