Skip to content

refactor: simplify job dispatch controller#839

Merged
adityachoudhari26 merged 17 commits intomainfrom
simplify-job-dispatch-controller
Mar 9, 2026
Merged

refactor: simplify job dispatch controller#839
adityachoudhari26 merged 17 commits intomainfrom
simplify-job-dispatch-controller

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Mar 7, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added configurable job dispatch queueing for improved job processing workflow.
    • Introduced service enablement control via environment variable for fine-grained feature management.
  • Refactor

    • Streamlined job dispatch reconciliation to directly work with job entities, reducing operational complexity and improving code maintainability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 7, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 30bc4d7d-d811-47f3-8ae5-7f3f7241a5e9

📥 Commits

Reviewing files that changed from the base of the PR and between e65e304 and 85e5107.

📒 Files selected for processing (24)
  • .github/workflows/apps-workspace-engine.yaml
  • apps/workspace-engine/pkg/config/env.go
  • apps/workspace-engine/pkg/db/convert.go
  • apps/workspace-engine/pkg/db/jobs.sql.go
  • apps/workspace-engine/pkg/db/queries/jobs.sql
  • apps/workspace-engine/pkg/reconcile/events/jobdispatch.go
  • apps/workspace-engine/pkg/workspace/jobagents/registry.go
  • apps/workspace-engine/pkg/workspace/releasemanager/deployment/executor_test.go
  • apps/workspace-engine/pkg/workspace/releasemanager/manager_test.go
  • apps/workspace-engine/pkg/workspace/releasemanager/verification/manager.go
  • apps/workspace-engine/pkg/workspace/workflowmanager/manager_test.go
  • apps/workspace-engine/pkg/workspace/workspace.go
  • apps/workspace-engine/svc/controllers/jobdispatch/controller.go
  • apps/workspace-engine/svc/controllers/jobdispatch/getters.go
  • apps/workspace-engine/svc/controllers/jobdispatch/getters_postgres.go
  • apps/workspace-engine/svc/controllers/jobdispatch/jobagents/deployment_agent_selector.go
  • apps/workspace-engine/svc/controllers/jobdispatch/jobagents/deployment_agent_selector_test.go
  • apps/workspace-engine/svc/controllers/jobdispatch/jobagents/registry.go
  • apps/workspace-engine/svc/controllers/jobdispatch/reconcile.go
  • apps/workspace-engine/svc/controllers/jobdispatch/reconcile_test.go
  • apps/workspace-engine/svc/controllers/jobdispatch/setters.go
  • apps/workspace-engine/svc/controllers/jobdispatch/setters_postgres.go
  • apps/workspace-engine/test/controllers/harness/mocks.go
  • apps/workspace-engine/test/controllers/harness/pipeline.go

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Walkthrough

This PR refactors the job dispatch system to use direct Job-based workflows instead of ReleaseTarget abstractions. It introduces a reconcile Queue-based optional job dispatch mechanism, simplifies data access patterns with granular getters (GetJob, GetRelease, GetDeployment, GetJobAgent), and removes legacy job agent selection logic.

Changes

Cohort / File(s) Summary
GitHub Actions Workflow
.github/workflows/apps-workspace-engine.yaml
Added SERVICES=none environment variable to multiple test steps to control service enablement during CI/CD execution.
Configuration & Service Gating
apps/workspace-engine/pkg/config/env.go, apps/workspace-engine/pkg/workspace/releasemanager/verification/manager.go
Introduced IsServiceEnabled() function to check if services are enabled via environment variable; added no-op guards in verification manager to skip processing when Job Verification Metric service is enabled.
Database Layer — Jobs & Conversions
apps/workspace-engine/pkg/db/queries/jobs.sql, apps/workspace-engine/pkg/db/jobs.sql.go, apps/workspace-engine/pkg/db/convert.go
Added UpdateJobStatus SQL operation and corresponding Go method; added ToOapiJobAgent and ToOapiJobFromGetJobByIDRow conversion helpers; extended ToOapiDeployment to unmarshal JobAgents from JSON.
Job Dispatch Event & Registry
apps/workspace-engine/pkg/reconcile/events/jobdispatch.go, apps/workspace-engine/pkg/workspace/jobagents/registry.go
Introduced JobDispatchParams, EnqueueJobDispatch function, and event handling; extended Registry to accept optional reconcile.Queue for job dispatch with shouldEnqueue and enqueueJobDispatch helpers.
Job Dispatch Controller — Interface & Data Access Refactoring
apps/workspace-engine/svc/controllers/jobdispatch/controller.go, apps/workspace-engine/svc/controllers/jobdispatch/getters.go, apps/workspace-engine/svc/controllers/jobdispatch/getters_postgres.go
Simplified data access from ReleaseTarget-based lookups to direct Job-based retrieval; replaced legacy getter methods with granular GetJob, GetRelease, GetDeployment, GetJobAgent accessors; implemented corresponding PostgreSQL query methods.
Job Dispatch — Reconciliation & Dispatching Logic
apps/workspace-engine/svc/controllers/jobdispatch/reconcile.go, apps/workspace-engine/svc/controllers/jobdispatch/setters.go, apps/workspace-engine/svc/controllers/jobdispatch/setters_postgres.go
Refactored Reconcile to accept Job instead of ReleaseTarget; added helper functions (getRelease, getDeployment, getJobAgents, getAgentSpecs) for modular flow; renamed CreateJobWithVerification to CreateVerifications; implemented UpdateJob to handle job status updates.
Job Agent Registry & Selection
apps/workspace-engine/svc/controllers/jobdispatch/jobagents/registry.go, apps/workspace-engine/svc/controllers/jobdispatch/jobagents/deployment_agent_selector.go (deleted), apps/workspace-engine/svc/controllers/jobdispatch/jobagents/deployment_agent_selector_test.go (deleted)
Updated Getter interface to use context-aware, UUID-based GetJobAgent; removed legacy GetEnvironment and GetResource methods; entirely removed DeploymentAgentsSelector type and its 830-line test suite (legacy CEL-based agent selection logic).
Test Files — Registry & Reconciliation Tests
apps/workspace-engine/svc/controllers/jobdispatch/reconcile_test.go, apps/workspace-engine/test/controllers/harness/mocks.go, apps/workspace-engine/test/controllers/harness/pipeline.go, apps/workspace-engine/pkg/workspace/releasemanager/deployment/executor_test.go, apps/workspace-engine/pkg/workspace/releasemanager/manager_test.go, apps/workspace-engine/pkg/workspace/workflowmanager/manager_test.go
Updated mocks to support new Job-based flow with GetJob, GetRelease, GetDeployment, GetJobAgent methods; added mockDispatcher for job dispatch verification; introduced DesiredReleaseSetter with job creation and enqueuing logic per agent; updated all NewRegistry calls to include optional queue parameter; refactored test helpers and scaffolding.
Workspace Initialization
apps/workspace-engine/pkg/workspace/workspace.go
Updated NewRegistry invocation to pass reconcileQueue as third parameter, wiring queue support into job agent registry initialization.

Sequence Diagram(s)

sequenceDiagram
    participant Controller as Job Dispatch<br/>Controller
    participant Getter as PostgresGetter
    participant DB as Database
    participant Reconcile as Reconcile<br/>Function
    participant Dispatcher as Job<br/>Dispatcher
    participant Setter as PostgresSetter

    Controller->>Getter: GetJob(ctx, jobID)
    Getter->>DB: Query job by ID
    DB-->>Getter: Job record
    Getter-->>Controller: *oapi.Job

    Controller->>Reconcile: Reconcile(ctx, getter, setter,<br/>verifier, dispatcher, job)
    
    Reconcile->>Getter: GetRelease(ctx, job.ReleaseId)
    Getter->>DB: Query release by ID
    DB-->>Getter: Release record
    Getter-->>Reconcile: *oapi.Release
    
    Reconcile->>Getter: GetDeployment(ctx, release.DeploymentId)
    Getter->>DB: Query deployment by ID
    DB-->>Getter: Deployment record
    Getter-->>Reconcile: *oapi.Deployment
    
    Reconcile->>Getter: GetJobAgents(ctx, release.Id)
    Getter->>DB: Query job agents for release
    DB-->>Getter: JobAgent records
    Getter-->>Reconcile: []oapi.JobAgent
    
    Reconcile->>Getter: GetVerificationPolicies(ctx, releaseTarget)
    Getter->>DB: Query policies & rules
    DB-->>Getter: VerificationMetricSpec list
    Getter-->>Reconcile: []oapi.VerificationMetricSpec
    
    Reconcile->>Dispatcher: Dispatch(ctx, job)
    Dispatcher-->>Reconcile: error (if any)
    
    Reconcile->>Setter: CreateVerifications(ctx, job, specs)
    Setter->>DB: Insert verification metrics
    DB-->>Setter: Completed
    Setter-->>Reconcile: error (if any)
    
    Reconcile-->>Controller: *ReconcileResult
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

Suggested reviewers

  • jsbroks

🐰 A rabbit bounces through the code with glee,
Jobs now flow straight, no targets to see!
Direct paths to dispatch, verification blooms,
Agents leap forward through reconcile's rooms! ✨🐇

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch simplify-job-dispatch-controller

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@adityachoudhari26 adityachoudhari26 marked this pull request as draft March 7, 2026 18:54
@adityachoudhari26 adityachoudhari26 marked this pull request as ready for review March 9, 2026 01:17
@adityachoudhari26 adityachoudhari26 merged commit 479392e into main Mar 9, 2026
7 of 9 checks passed
@adityachoudhari26 adityachoudhari26 deleted the simplify-job-dispatch-controller branch March 9, 2026 01:17
zacharyblasczyk added a commit that referenced this pull request Mar 9, 2026
Replace panic-prone uuid.MustParse calls with proper uuid.Parse error
handling across stable production code in workspace-engine. This prevents
runtime panics from invalid UUID strings by returning descriptive errors
instead.

Follows the pattern established in commit 5888d08.

Scope:
- pkg/store/ (environment, deployment, resource, system, policies, resources)
- svc/controllers/jobverificationmetric/ (getters and setters)
- svc/controllers/environmentresourceselectoreval/controller.go
- pkg/workspace/releasemanager/policy/evaluator/ (approval, deploymentwindow,
  environmentprogression, versioncooldown)

Excluded:
- svc/controllers/jobdispatch/ (in flux from #839)
- Functions that don't return error (would require interface changes)
- Test files
- deploymentdependency evaluator (functions don't return error)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant