Background Jobs
Cron jobs trigger API routes to process queued operations and scheduled tasks.Terra has two types of background processing:
- Queue Processor — Processes async operations (webhooks, emails, Airtable syncs)
- Lifecycle Worker — Handles scheduled form lifecycle events (auto-publish, auto-close)
Queue Processor
The queue processor handles async operations that were enqueued during form submission.Operation Types
Lifecycle Worker
The lifecycle worker handles scheduled form events and cleanup tasks.Task Breakdown
| Task | Description | Frequency |
|---|---|---|
processScheduledPublishes | Publishes forms where published_at has passed | Every minute |
processScheduledCloses | Closes forms where closes_at has passed | Every minute |
processAutoFreeze | Freezes forms after first submission | Every minute |
cleanupExpiredSessions | Removes abandoned draft sessions (7+ days) | Every minute |
cleanupSoftDeletedRecords | Permanently deletes 30+ day old soft-deleted records | Every minute |
Scheduled Publishing
Forms can be scheduled to publish automatically:Form Auto-Freezing
Forms are automatically frozen after receiving their first submission:Cron Configuration
Both workers are triggered via Vercel Cron Jobs:API Endpoints
| Endpoint | Purpose | Method |
|---|---|---|
/api/queue/process | Process async operations queue | GET |
/api/cron/worker | Run lifecycle and cleanup tasks | GET/POST |
Monitoring
Queue Health
Worker Health
The worker returns detailed results:Error Handling
Both workers handle errors gracefully:- Per-item isolation: One failed operation doesn’t block others
- Logging: All errors are logged with context
- Retry logic: Queue operations retry with exponential backoff
- Dead letter: Persistently failing operations are marked as failed