Skip to Content
AutomateCron Jobs

Cron Jobs

Cron jobs are JavaScript code snippets stored in the database and executed on a schedule using standard cron expressions. They run server-side with access to all platform services. On the Buildpad Engine backend, the Engine stores the jobs and runs them. The Studio’s server runs no job.

Manage jobs on the Cron Jobs page of the Studio. The list shows each job’s schedule, timezone, status, last run and next run.

Cron Jobs page with three jobs, their schedules and next run times

Click a job to edit its code and settings. Run Now runs the job at once, and the History tab shows each run with its duration, status, trigger and log lines.

Cron job editor with the job code and the Job Settings panel

History tab of a cron job with one successful manual run

Database Schema

daas_cron_jobs

ColumnTypeDescription
iduuidPrimary key
nametextHuman-readable name
descriptiontextOptional description
scheduletext5-field cron expression
timezonetextIANA timezone (e.g., Asia/Singapore)
codetextJavaScript code to execute
statustextactive or inactive
timeout_msintegerMaximum execution time in ms
memory_limit_mbintegerSandbox memory limit in MB (default 64). The Engine records this value but does not apply it. The timeout stops a run
runningbooleanLock flag — true while executing
running_sincetimestamptzWhen the current run started
last_run_attimestamptzLast execution time
last_run_statustextrunning, success, error, or timeout
next_run_attimestamptzCalculated next run time

daas_cron_history

ColumnTypeDescription
iduuidPrimary key
job_iduuidFK → daas_cron_jobs
job_nametextJob name at time of run (denormalized)
triggered_attimestamptzWhen the job was scheduled to fire
started_attimestamptzWhen execution actually began
finished_attimestamptzWhen execution ended
duration_msintegerTotal execution time
statustextrunning, success, error, or timeout
errortextError message if failed
logstext[]Lines captured from console.log
triggered_bytextschedule, manual, or extension

Cron Expression Reference

ExpressionMeaning
* * * * *Every minute
0 * * * *Every hour
0 0 * * *Every day at midnight
0 9 * * 1Every Monday at 9:00 AM
*/15 * * * *Every 15 minutes
0 0 1 * *First day of every month
0 6,18 * * *6 AM and 6 PM daily

The Engine also accepts the descriptors such as @hourly and @daily. It reads the schedule in the job’s timezone.

Code Sandbox

Each job runs in an isolated sandbox with these globals:

AvailableNot available
context — job metadatasetTimeout / setInterval
services — platform servicesrequire / import
console.log/warn/error/infoeval
Standard JS globalsFile system access

Available services

// Items CRUD const svc = await services.items('articles'); await svc.readByQuery({ filter: { status: { _eq: 'draft' } } }); await svc.createOne({ title: 'Auto-generated' }); await svc.updateOne(id, { processed: true }); await svc.deleteOne(id); // Schema services await services.collections(); await services.fields(); await services.relations(); // Files and versions await services.files(); await services.versions(); // Send email await services.mail({ to: 'user@example.com', subject: 'Report', html: '<p>Done</p>' }); // Trigger another cron job await services.cron.trigger('job-id-or-name'); // Whitelisted environment variables const apiKey = services.env.MY_API_KEY; // Safe HTTP (domain-restricted — configure EXTENSION_ALLOWED_DOMAINS) const res = await services.fetch('https://api.example.com/data'); // Custom services const notifier = await services.custom('slack-notify'); // Raw Supabase (bypasses RLS — use with caution). Supabase backend only. const { data } = await services.supabase.from('table').select('*');

On the Buildpad Engine backend:

  • services.supabase is not available. A call throws RUNTIME_SUPABASE_UNAVAILABLE. Use services.items(collection) instead.
  • services.items(collection).readByQuery() returns the array of items, not a { data, meta } object. A query key that the Items API does not know is refused, not ignored.
  • A job runs as the system principal, an administrator. services.items applies that principal’s permissions.
  • context holds jobId, jobName, triggeredBy (schedule, manual or extension), runId (the id of the history row) and scheduledAt.
  • services.fetch reaches only the hosts in the Engine’s EXTENSION_ALLOWED_DOMAINS. With no value, only loopback addresses are reachable.

Example: Cleanup old records

// Delete items older than 30 days const cutoff = new Date(); cutoff.setDate(cutoff.getDate() - 30); const svc = await services.items('daas_activity'); const old = await svc.readByQuery({ filter: { timestamp: { _lt: cutoff.toISOString() } }, fields: ['id'], limit: 500, }); for (const row of old) { await svc.deleteOne(row.id); } console.log(`Cleaned up ${old.length} old activity records`);

REST API

MethodPathDescription
GET/api/cronList cron jobs
POST/api/cronCreate cron job
GET/api/cron/:idGet cron job
PATCH/api/cron/:idUpdate cron job
DELETE/api/cron/:idDelete cron job
POST/api/cron/:id/runTrigger job manually
POST/api/cron/:id/cloneClone a job (always created inactive)
GET/api/cron/:id/historyGet history for one job
GET/api/cron/historyGet all job history

The running lock prevents concurrent executions of the same job. If a job times out without clearing the lock, use PATCH /api/cron/:id to set running: false.

On the Buildpad Engine backend:

  • Run now. POST /api/cron/:id/run runs the job to the end before it answers. The answer holds data.historyId and data.message. historyId is empty when another run held the lock and the Engine skipped this one. The route also runs an inactive job.
  • Who can manage jobs. An administrator, or a user whose policy grants the action on daas_cron_jobs: read for the list, a job and the history, create (and read) for create and clone, update for update and run now, and delete for delete. The row filter of the permission applies. A job outside it answers 404, as if it does not exist. Give update with care: run now executes the job’s code as an administrator.
  • MCP. An administrator’s agent can manage jobs with the cron tool. See Available Tools.

Scheduling

The Engine runs the scheduler. Each active job fires on its schedule. The Studio’s server starts no scheduler on this backend.

  • One run for each tick. The Engine takes a lock on the job in the database before it runs it. If several Engine processes run, only one of them runs the job for each tick.
  • Changes apply without a restart. When you create, update, activate, deactivate or delete a job, every Engine process applies the change. With Valkey, this is immediate. Without Valkey, it takes up to 30 seconds.
  • A job with broken code is skipped. If the stored code does not compile, the scheduler logs the job’s name and loads the other jobs. The API refuses to save code that does not compile, with 400.
  • Turn the schedule off with the Engine’s CRON_ENABLED=false. Run now still works.
  • The history keeps the most recent runs of each job and removes the older ones.

In production the app runs as a multi-process cluster (one worker per core). The cron scheduler runs on a single leader worker, so each job fires exactly once per tick regardless of worker count; if the leader worker exits, another worker takes over scheduling. Creating, updating, activating, or deleting a job via the API takes effect immediately — the change is relayed to the leader over the cluster message bus, whichever worker served the request.

Cron console.log output is captured into the job’s history (logs), which is stored in the database and visible from any worker. The in-memory Logs page, however, only shows output from the worker serving your request — see Logs.