Add workspace lifecycle management via task-complete callback
Publish Image / publish (push) Successful in 20s

- Workspaces curl POST /webhook/task-complete/{name} when done
- Orchestrator deletes the workspace via Coder API on callback
- Active workspaces count toward concurrency limit
- GET /queue now shows active workspaces with elapsed time
- Coder template gains callback_url parameter
- TTL becomes a safety net, not the primary shutdown mechanism

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Daniel Samson
2026-04-12 13:37:08 +01:00
co-authored by Claude Opus 4.6
parent f23fb4e2e0
commit 7145fb536a
5 changed files with 167 additions and 7 deletions
+22
View File
@@ -208,6 +208,15 @@ data "coder_parameter" "anthropic_api_key" {
mutable = false
}
data "coder_parameter" "callback_url" {
name = "callback_url"
display_name = "Task Complete Callback URL"
description = "URL to POST when task finishes (set by orchestrator)"
type = "string"
default = ""
mutable = false
}
data "coder_parameter" "deploy_env" {
name = "deploy_env"
display_name = "Deploy Environment"
@@ -443,6 +452,7 @@ resource "coder_agent" "main" {
ISSUE_NUMBER = data.coder_parameter.issue_number.value
REPO_CLONE_URL = data.coder_parameter.repo_clone_url.value
DEPLOY_ENV = data.coder_parameter.deploy_env.value
CALLBACK_URL = data.coder_parameter.callback_url.value
}
startup_script = <<-EOT
@@ -519,6 +529,13 @@ resource "coder_agent" "main" {
claude --print --dangerously-skip-permissions "/project:$TASK_TYPE $ARGS" 2>&1 | tee ~/task-output.log
echo "Task completed. Output saved to ~/task-output.log"
# Notify orchestrator that the task is done
if [ -n "$CALLBACK_URL" ]; then
curl -s -X POST -H "Content-Type: application/json" \
-d '{"status":"complete"}' \
"$CALLBACK_URL" || echo "Callback failed (non-fatal)"
fi
fi
EOT
}
@@ -657,6 +674,11 @@ resource "kubernetes_deployment_v1" "workspace" {
value = data.coder_parameter.deploy_env.value
}
env {
name = "CALLBACK_URL"
value = data.coder_parameter.callback_url.value
}
resources {
requests = {
cpu = "${tonumber(data.coder_parameter.cpu.value) * 500}m"