HCTHE HCLAB

Background jobs

Background processing uses HTTP cron routes secured by CRON_SECRET.

Endpoints

Route Scope
GET /api/cron/research-ops Runs all jobs sequentially
GET /api/cron/process-events Event queue only
GET /api/cron/process-webhooks Study status webhooks
GET /api/cron/run-export-schedules Scheduled study exports

Authentication

When CRON_SECRET is set, requests must include:

Authorization: Bearer <CRON_SECRET>

Without a secret, routes may be open — always set CRON_SECRET in production.

Vercel Cron example

{
  "crons": [
    {
      "path": "/api/cron/research-ops",
      "schedule": "*/15 * * * *"
    }
  ]
}

Add the Authorization header in vercel.json cron configuration or use Vercel's cron secret integration.

Event queue

Research events (enrollment, task completion, etc.) enqueue to EventLog for async processing. Set:

EVENT_QUEUE_DISABLED=true

to process synchronously during debugging.

Export schedules

Studies can configure recurring exports. The export scheduler generates files and optionally uploads to S3 when EXPORT_S3_* variables are configured.

Manual trigger (dev)

curl -H "Authorization: Bearer $CRON_SECRET" \
  http://localhost:3000/api/cron/research-ops

Monitoring

Check /admin/events for processed events and errors. Failed webhook deliveries can be retried from study admin when configured.