Skip to main content

Cron Job

Cron Jobs are scheduled automation scripts that execute JavaScript code at regular intervals. They enable organizations to automate data synchronization, calculations, notifications, and integrations with external systems.

At a Glance

  • JavaScript code runs in a secure sandbox environment
  • Configurable schedules: 5m, 10m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, daily, weekly
  • Access to organization data, database operations, HTTP client, and email
  • Environment variables and encrypted secrets support
  • 5-minute maximum execution time
  • Manual trigger option for testing

Data Shape

Sandbox Environment

Your JavaScript code runs in an isolated sandbox with access to these APIs:

Example Code

Security & Permissions

  • Create/Update/Delete: Owner role required
  • View/Execute: Any organization member
  • Sandbox: Code runs in isolated VM with no file system access
  • RLS: Database queries respect row-level security policies
  • Secrets: Encrypted at rest using organization’s encryption key
  • Timeout: Automatic termination after 5 minutes

Execution Flow

  1. Scheduler finds jobs where nextExecutionAt <= now and isActive = true
  2. Job code is executed in a secure sandbox
  3. Execution result (success/failure, logs, output) is recorded
  4. nextExecutionAt is calculated based on schedule
  5. lastExecutionAt is updated

API Notes

  • cronJob.list: Returns jobs with execution statistics and variable counts
  • cronJob.get: Returns full job details including code and recent executions
  • cronJob.create: Creates new job (starts inactive for safety)
  • cronJob.execute: Manually trigger execution (useful for testing)
  • cronJob.toggle: Enable/disable scheduled execution
  • CronJobVariable - Environment variables and secrets for jobs
  • CronJobExecution - Execution history and logs