rdev/cookbooks/trees/slackpath-2-async-worker-pipeline.yaml
jordan 853ec4cf81 fix: go.work race condition with batch components and idempotent provisioning
Three coordinated fixes for CI pipeline race conditions:

1. Woodpecker step dependencies: Added depends_on: [deps] to all 6 component
   templates (service, worker, cli, app-astro, app-react, app-nextjs) so build
   steps wait for go work sync to complete.

2. Idempotent resource provisioning: Modified provisionResources() to check
   for existing database/cache before creating, preventing "already exists"
   errors on component re-adds.

3. Batch component endpoint: POST /projects/{id}/components/batch enables
   atomic multi-component additions in a single git commit. Validates all
   components upfront, provisions infra sequentially, commits code components
   atomically.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 12:31:40 -07:00

128 lines
3.8 KiB
YAML

name: async-worker-pipeline
description: "Slack Path 2: Background Workers. Implements Producer/Consumer pattern with Redis."
version: 1
vars:
project_name: ""
feature_slug: "async-jobs"
steps:
# --- Infrastructure ---
create-project:
action: api
method: POST
endpoint: /project
body:
name: "{{ .vars.project_name }}"
description: "Slack Path 2: Async Workers"
outputs:
- project_id: .data.name
- domain: .data.domain
add-redis:
description: Add Redis for job queue (may already exist from skeleton)
depends_on: [create-project]
on_error: continue
action: api
method: POST
endpoint: "/projects/{{ .outputs.create-project.project_id }}/components"
body:
type: redis
name: "job-queue"
add-api:
description: Public API (Producer)
depends_on: [create-project, add-redis]
action: api
method: POST
endpoint: "/projects/{{ .outputs.create-project.project_id }}/components"
body:
type: service
name: "api"
add-worker:
description: Worker Service (Consumer)
depends_on: [create-project, add-redis]
action: api
method: POST
endpoint: "/projects/{{ .outputs.create-project.project_id }}/components"
body:
type: worker
name: "background-processor"
wait-infra:
depends_on: [create-project, add-api, add-worker]
action: wait_pipeline
project_id: "{{ .outputs.create-project.project_id }}"
# --- Implementation ---
implement-queue:
description: "Agent implements Job Queue logic in API and Worker"
depends_on: [create-project, wait-infra]
action: api
method: POST
endpoint: "/projects/{{ .outputs.create-project.project_id }}/builds"
body:
prompt: "/implement-feature {{ .vars.feature_slug }} --requirements 'API: POST /jobs pushes JSON to Redis. Worker: Pops from Redis, simulates work, updates status. API: GET /jobs/{id} returns status.'"
auto_commit: true
auto_push: true
git_clone_url: "https://git.threesix.ai/jordan/{{ .outputs.create-project.project_id }}.git"
outputs:
- build_id: .data.task_id
wait-code:
description: Wait for agent code generation
depends_on: [implement-queue]
action: wait_build
build_id: "{{ .outputs.implement-queue.build_id }}"
max_attempts: 120
poll_interval: 5
wait-deploy:
depends_on: [create-project, wait-code]
action: wait_pipeline
project_id: "{{ .outputs.create-project.project_id }}"
# --- Verification ---
verify-service-running:
description: "Verify API service is running"
depends_on: [create-project, wait-deploy]
action: shell
command: |
DOMAIN="{{ .outputs.create-project.domain }}"
HEALTH=$(curl -s "https://$DOMAIN/api/api/health" | jq -r '.data.status // empty')
if [ "$HEALTH" == "healthy" ]; then
echo "API service healthy"
exit 0
else
echo "Fail: API service not healthy"
exit 1
fi
verify-async:
description: "Create Job -> Verify Acceptance -> Poll for Completion (optional)"
depends_on: [create-project, verify-service-running]
on_error: continue
action: shell
command: |
DOMAIN="{{ .outputs.create-project.domain }}"
# 1. Enqueue
JOB_ID=$(curl -s -X POST "https://$DOMAIN/api/jobs" -d '{"type":"image_resize"}' | jq -r .id)
echo "Job enqueued: $JOB_ID"
# 2. Poll for completion (Worker should pick it up)
for i in {1..10}; do
STATUS=$(curl -s "https://$DOMAIN/api/jobs/$JOB_ID" | jq -r .status)
echo "Job status: $STATUS"
if [ "$STATUS" == "completed" ]; then exit 0; fi
sleep 2
done
echo "Job never completed"
exit 1
teardown:
- action: api
method: DELETE
endpoint: "/project/{{ .outputs.create-project.project_id }}"