Files
stack/docs/scratchpads/167-runner-jobs-crud.md
Jason Woltje efe624e2c1 feat(#168): Implement job steps tracking
Implement JobStepsModule for granular step tracking within runner jobs.

Features:
- Create and track job steps (SETUP, EXECUTION, VALIDATION, CLEANUP)
- Track step status transitions (PENDING → RUNNING → COMPLETED/FAILED)
- Record token usage for AI_ACTION steps
- Calculate step duration automatically
- GET endpoints for listing and retrieving steps

Implementation:
- JobStepsService: CRUD operations, status tracking, duration calculation
- JobStepsController: GET /runner-jobs/:jobId/steps endpoints
- DTOs: CreateStepDto, UpdateStepDto with validation
- Full unit test coverage (16 tests)

Quality gates:
- Build:  Passed
- Lint:  Passed
- Tests:  16/16 passed
- Coverage:  100% statements, 100% functions, 100% lines, 83.33% branches

Also fixed pre-existing TypeScript strict mode issue in job-events DTO.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 21:16:23 -06:00

3.2 KiB

Issue #167: Runner jobs CRUD and queue submission

Objective

Implement runner-jobs module for job lifecycle management and queue submission, integrating with BullMQ for async job processing.

Prerequisites

  • #164 (Database schema) - RunnerJob model available
  • #165 (BullMQ module) - BullMqService available for queue submission

Approach

  1. Review existing CRUD patterns (tasks, events modules)
  2. Review RunnerJob schema and BullMqService interface
  3. Follow TDD: Write tests first (RED phase)
  4. Implement service layer with Prisma + BullMQ integration (GREEN phase)
  5. Implement controller layer (GREEN phase)
  6. Refactor and optimize (REFACTOR phase)
  7. Run quality gates (typecheck, lint, build, test)

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

Progress

  • Review existing patterns and dependencies
  • Create DTOs (CreateJobDto, QueryJobsDto)
  • Write service tests (RED phase)
  • Implement service with Prisma + BullMQ (GREEN phase)
  • Write controller tests (RED phase)
  • Implement controller (GREEN phase)
  • Create module configuration
  • Run quality gates (typecheck, lint, build, test)
  • Commit changes

Quality Gates Results

  • Typecheck: PASSED
  • Lint: PASSED (auto-fixed formatting)
  • Build: PASSED
  • Tests: PASSED (24/24 tests passing)

Testing

  • Unit tests for RunnerJobsService
  • Unit tests for RunnerJobsController
  • Mock BullMqService for queue operations
  • Mock Prisma for database operations
  • Target: ≥85% coverage

Implementation Summary

Files Created:

  • apps/api/src/runner-jobs/dto/create-job.dto.ts - Job creation DTO
  • apps/api/src/runner-jobs/dto/query-jobs.dto.ts - Job query DTO
  • apps/api/src/runner-jobs/dto/index.ts - DTO barrel export
  • apps/api/src/runner-jobs/runner-jobs.service.ts - Service implementation
  • apps/api/src/runner-jobs/runner-jobs.service.spec.ts - Service tests (18 tests)
  • apps/api/src/runner-jobs/runner-jobs.controller.ts - Controller implementation
  • apps/api/src/runner-jobs/runner-jobs.controller.spec.ts - Controller tests (6 tests)
  • apps/api/src/runner-jobs/runner-jobs.module.ts - Module configuration
  • apps/api/src/runner-jobs/index.ts - Module barrel export

Key Implementation Details:

  1. Used Prisma relations (workspace.connect, agentTask.connect) for foreign keys
  2. Optional fields only included when present (result, agentTaskId)
  3. BullMQ integration for async job processing via QUEUE_NAMES.RUNNER
  4. Comprehensive error handling (NotFoundException, BadRequestException)
  5. Following existing patterns from tasks/events modules

Test Coverage:

  • Service: 18 tests covering create, findAll, findOne, cancel, retry
  • Controller: 6 tests covering all endpoints
  • Total: 24 tests, all passing

Token Usage Estimate: ~76,000 tokens

Notes

  • Followed existing CRUD patterns from tasks/events modules
  • Used DTOs for validation
  • Integrated with BullMqService for queue submission
  • Used Prisma for all database operations
  • Followed PDA-friendly language principles in responses