Cron Jobs
PaperDB provides a built-in cron job engine. Schedule tasks using standard cron expressions or friendly natural language like every 5 minutes or daily at 9am.
Scheduling a Job
curl -X POST https://api.paperdb.app/cron \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
"name": "Daily Cleanup",
"schedule": "0 0 * * *",
"timezone": "UTC",
"action": {
"type": "http",
"method": "POST",
"url": "https://your-server.com/api/cleanup"
}
}'Human-readable schedules are also accepted: "every 5 minutes", "every hour", "daily at 9am", "weekdays at 8:30am", "weekly", "monthly".
Cron jobs run at most once per minute. Sub-minute schedules are not supported.
Action Types
HTTP Action
Makes an HTTP request to an external endpoint. Supports custom headers and a JSON body.
"action": {
"type": "http",
"method": "POST",
"url": "https://api.example.com/sync",
"headers": {
"Authorization": "Bearer token"
},
"body": { "source": "cron" }
}Collection Action
Performs a database operation on a collection. Requires an apiKey in the action config so the worker can authenticate against the API.
// Delete matching documents
"action": {
"type": "collection",
"collection": "sessions",
"operation": "delete",
"filter": { "expiresAt": { "lt": "2024-01-01" } },
"apiKey": "your_api_key"
}
// Update matching documents
"action": {
"type": "collection",
"collection": "users",
"operation": "update",
"filter": { "status": "trial" },
"data": { "status": "expired" },
"apiKey": "your_api_key"
}The function action type (edge functions) is not yet available. Creating a cron job with "type": "function" returns 501 Not Implemented.
Managing Jobs via SDK
// Create
const job = await db.cron.create({
name: "Nightly sync",
schedule: "daily at midnight",
action: { type: "http", url: "https://example.com/sync", method: "POST" }
});
// List
const jobs = await db.cron.list();
// Trigger immediately
const run = await db.cron.trigger(job.id);
// Get run history
const runs = await db.cron.getRuns(job.id, { limit: 20 });
// Disable / enable
await db.cron.disable(job.id);
await db.cron.enable(job.id);
// Delete
await db.cron.delete(job.id);