feat: job registry — scalable job architecture#79
Conversation
Add a central Job Registry that makes adding a new job type require only 2-3 file changes instead of 15+. ## Core changes - New `packages/core/src/jobs/job-registry.ts` with IJobDefinition, JOB_REGISTRY (6 jobs), and utility functions: getJobDef, getAllJobDefs, getJobDefByCommand, getJobDefByLogName, getValidJobTypes, getDefaultQueuePriority, getLogFileNames, getLockSuffix, normalizeJobConfig, buildJobEnvOverrides, camelToUpperSnake - VALID_JOB_TYPES, DEFAULT_QUEUE_PRIORITY, LOG_FILE_NAMES in constants.ts now derived from registry instead of hardcoded - config-normalize.ts: replace per-job qa/audit/analytics blocks with registry loop - config-env.ts: replace NW_QA_*/NW_AUDIT_*/NW_ANALYTICS_* blocks with registry loop ## Web changes - web/utils/jobs.ts: add IWebJobDefinition, WEB_JOB_REGISTRY (with getEnabled, getSchedule, buildEnabledPatch per job), getWebJobDef() - web/api.ts: add generic triggerJob(jobId) function - web/store/useStore.ts: add IWebJobState and getJobStates() computed getter - web/pages/Scheduling.tsx: replace handleJobToggle if/else chain and triggerMap with registry-driven code - web/store/useStore.ts: Zustand jobs computed slice ## Server changes - action.routes.ts: replace qa/audit/analytics/planner route handlers with JOB_REGISTRY loop Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
DiffGuard AI AnalysisAI Review Summary🏆 Overall Score: 88/100 This PR introduces a well-designed Job Registry pattern that centralizes job metadata, defaults, and configuration logic into a single source of truth. The implementation is clean, thoroughly tested, and maintains backward compatibility. ✅ Key Strengths
🔚 Conclusion Analyzed using z-ai/glm-5 |
Remove unused Provider type import that was flagged by ESLint. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
DiffGuard AI AnalysisAI Review Summary🏆 Overall Score: 82/100 This PR introduces a well-architected Job Registry pattern that centralizes job metadata, defaults, and configuration handling. The implementation significantly improves maintainability and extensibility, though there are some integration gaps and minor code quality issues. ✅ Key Strengths
🐛 Bugs Found
📋 Issues Found
🔚 Conclusion This is a solid architectural refactor that will pay dividends in maintainability. The Job Registry pattern is well-implemented with excellent test coverage. Addressing the unused Analyzed using z-ai/glm-5 |
…on in triggerJob - Remove `migrateLegacy` field from IJobDefinition interface and all 6 registry entries — the functions were defined and tested but never called in production code, creating false confidence about legacy migration coverage - Remove corresponding migrateLegacy test block (tests for dead code) - Fix `triggerJob` in web/api.ts: replace hardcoded endpointMap (which duplicated WEB_JOB_REGISTRY.triggerEndpoint) with a lookup via getWebJobDef() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Closes #75
Summary
JOB_REGISTRY(inpackages/core/src/jobs/job-registry.ts) as the single source of truth for all job metadata — adding a new job now requires touching only 2-3 files instead of 15+config-normalize.ts) and env overrides (config-env.ts) now use generic registry loops instead of per-job if/else blocks for qa/audit/analyticsWEB_JOB_REGISTRY(web/utils/jobs.ts) provides UI metadata (triggerEndpoint, getEnabled, getSchedule, buildEnabledPatch) consumed by Scheduling page and Zustand storeScheduling.tsxhandleJobToggleandhandleTriggerJobnow registry-driven (no more triggerMap / if/else chains)action.routes.tsgenerates qa/audit/analytics/planner routes from registry loopTest plan
yarn workspace @night-watch/core test --run)yarn verifypasses clean across all packagestsc --noEmit)packages/core/src/__tests__/jobs/job-registry.test.ts(normalizeJobConfig, buildJobEnvOverrides, camelToUpperSnake, migrateLegacy for all 6 jobs)🤖 Generated with Claude Code