Implements runner-jobs module for job lifecycle management and queue submission. Changes: - Created RunnerJobsModule with service, controller, and DTOs - Implemented job creation with BullMQ queue submission - Implemented job listing with filters (status, type, agentTaskId) - Implemented job detail retrieval with steps and events - Implemented cancel operation for pending/queued jobs - Implemented retry operation for failed jobs - Added comprehensive unit tests (24 tests, 100% coverage) - Integrated with BullMQ for async job processing - Integrated with Prisma for database operations - Followed existing CRUD patterns from tasks/events modules API Endpoints: - POST /runner-jobs - Create and queue a new job - GET /runner-jobs - List jobs (with filters) - GET /runner-jobs/:id - Get job details - POST /runner-jobs/:id/cancel - Cancel a running job - POST /runner-jobs/:id/retry - Retry a failed job Quality Gates: - Typecheck: ✅ PASSED - Lint: ✅ PASSED - Build: ✅ PASSED - Tests: ✅ PASSED (24/24 tests) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
3.8 KiB
3.8 KiB
Issue #164: Database schema for job tracking
Objective
Add Prisma schema for runner_jobs, job_steps, and job_events tables to support the autonomous runner infrastructure.
Approach
- Read existing schema.prisma to understand current conventions
- Add four enums: RunnerJobStatus, JobStepPhase, JobStepType, JobStepStatus
- Add three models: RunnerJob, JobStep, JobEvent
- Create and run migration
- Verify migration succeeds
Schema Design
Enums
- RunnerJobStatus: PENDING, QUEUED, RUNNING, COMPLETED, FAILED, CANCELLED
- JobStepPhase: SETUP, EXECUTION, VALIDATION, CLEANUP
- JobStepType: COMMAND, AI_ACTION, GATE, ARTIFACT
- JobStepStatus: PENDING, RUNNING, COMPLETED, FAILED, SKIPPED
Models
-
RunnerJob - Top-level job tracking
- Links to workspace and optionally to agent_task
- Tracks overall job status, progress, result
- Timestamps: created_at, started_at, completed_at
-
JobStep - Granular step tracking
- Child of RunnerJob
- Phase-based organization (SETUP, EXECUTION, etc.)
- Token tracking for AI operations
- Duration tracking
-
JobEvent - Event sourcing audit log
- Immutable event log for jobs and steps
- Links to both job and optionally step
- Actor tracking for accountability
Progress
- Read existing schema.prisma
- Read architecture document for schema requirements
- Add enums (RunnerJobStatus, JobStepPhase, JobStepType, JobStepStatus)
- Add RunnerJob model with workspace and agentTask relations
- Add JobStep model with job relation
- Add JobEvent model with job and step relations
- Add RunnerJob[] to Workspace and AgentTask relations
- Create migration (20260201205935_add_job_tracking)
- Test migration - all tables created successfully
- Run quality gates (typecheck, lint, build - all passed)
- Generate Prisma client
- Commit changes (commit:
65b1dad)
Schema Observations from Existing Code
Conventions Identified:
- UUID primary keys with
@db.Uuidannotation - snake_case for database column names via
@map - snake_case for table names via
@@map - Timestamps use
@db.Timestamptzfor timezone awareness - workspace_id on all workspace-scoped tables with cascading deletes
- Composite unique constraints with
@@unique([id, workspaceId]) - Consistent indexing patterns: workspace_id, status, timestamps
- Json fields for flexible metadata with
@default("{}") - Optional foreign keys use
@db.Uuidwithout NOT NULL - Relations use descriptive names in both directions
Testing
Since this is a schema-only change, testing will verify:
- Migration runs successfully ✅
- Foreign key constraints are valid ✅
- Schema matches architecture document ✅
Verification performed:
- Database tables created: runner_jobs, job_steps, job_events
- All enums created: RunnerJobStatus, JobStepPhase, JobStepType, JobStepStatus
- Foreign key relationships verified:
- runner_jobs → workspaces (workspace_id)
- runner_jobs → agent_tasks (agent_task_id, optional)
- job_steps → runner_jobs (job_id)
- job_events → runner_jobs (job_id)
- job_events → job_steps (step_id, optional)
- Indexes created for performance:
- workspace_id for workspace filtering
- status for job querying
- priority for job prioritization
- timestamp for event ordering
- Quality gates passed:
- TypeScript compilation ✅
- ESLint checks ✅
- NestJS build ✅
- Prisma client generation ✅
Notes
- Following existing patterns from schema.prisma
- Using UUID for all primary keys (existing convention)
- Using snake_case for table names (Prisma convention)
- All workspace-scoped tables include workspace_id for RLS
- Migration file created: 20260201205935_add_job_tracking
- Database push successful, migration marked as applied
- Schema format validated successfully