Job Execution
Job Execution Overview
How Tendril claims and executes each job type.
Job Execution
All jobs share the same claiming mechanism and credential handling, but differ in what they execute. For the queue mechanics, see Job Queue Pattern.
Claiming
Every 10 seconds, the Tendril calls POST /api/jobs/claim. The server runs claim_next_job() — a PostgreSQL function using FOR UPDATE SKIP LOCKED for atomic, exactly-once claiming.
If a job is returned, the Tendril:
- Updates status to PROCESSING
- Reads the vine configuration and cloud identity from the job
- Assumes cloud credentials (details)
- Executes job-type-specific logic
- Updates status to SUCCESS or FAILED
Job Types
Plan Jobs
terraform plan + Infracost analysis
Deploy Jobs
terraform apply + ArgoCD installation
Destroy Jobs
terraform destroy + cleanup
Worker Jobs
DEPLOY_WORKER, UPDATE_WORKER, DESTROY_WORKER, CONNECTION_TEST
Error Handling
When any step fails:
- Error logged to STDERR stream
- Job status set to FAILED with error message
- Terraform state preserved (partial apply state saved to Supabase S3)
- Cloud credentials cleared (deferred cleanup always runs)
- Tendril returns to the poll loop for the next job
Users can retry failed jobs — since state is preserved, retries continue from the last successful resource rather than starting over.