Add startup health check to prevent silent scheduler failure on non-default PORT#665
Add startup health check to prevent silent scheduler failure on non-default PORT#665itsmiso-ai wants to merge 1 commit into
Conversation
…efault PORT The scheduler now calls a new `schedulerHealthCheck` function at startup which fetches `/api/health` using the configured bearer token. This verifies the scheduler can reach its own endpoints before periodic jobs begin firing. The health check returns true on HTTP 200 and false otherwise, logging descriptive errors via the injected deps.log. It does not prevent the scheduler from running — it provides visibility into misconfiguration without blocking periodic work. Fixes #653 Signed-off-by: Saffron <[email protected]>
3ef034c to
67cb1b4
Compare
Superseded by a newer automated review for this pull request.
There was a problem hiding this comment.
AI Automated Review
Full PR review.
Analysis engine: self-hosted@https://litellm.jory.dev/v1 (openai) — primary route
Recommendation: Approve. The PR successfully implements a startup health check to verify scheduler reachability, directly addressing the silent failure risk on non-default ports.
Change-by-Change Findings
src/lib/scheduler.ts: AddsschedulerHealthCheckwhich fetches${config.baseUrl}/api/healthwith bearer auth. Correctly handles network errors and non-200 responses by logging failures without blocking job execution. Invocation inside thesetTimeoutcallback ensures it runs after the configured startup delay.src/lib/scheduler.test.ts: Updates the existingstartSchedulertest to expect two fetch calls (health check + job) and adds a dedicated test suite forschedulerHealthCheckcovering success, HTTP error, and network failure scenarios. Aligns with repository testing conventions.
Sources
- PR Diff:
src/lib/scheduler.ts,src/lib/scheduler.test.ts - Linked Issue: PR 653
- CI Status: All checks passed for commit
67cb1b4
Standards Compliance
- Follows the mandated
error instanceof Errorpattern for safe error message extraction. - Uses dependency injection (
deps.fetch,deps.log) consistently with existing scheduler architecture. - No secrets, environment variables, or build artifacts are committed.
- CI checks (Typecheck, Lint, Tests, Build, Docker) all passed successfully.
Linked Issue Fit
- Addresses PR 653 acceptance criteria by adding a startup health check that verifies the scheduler can reach its own endpoints before arming periodic jobs. The
PORTresolution logic appears already handled inschedulerConfigFromEnv(existing tests confirmbaseUrlcorrectly respects thePORTenv var), so this PR completes the visibility requirement to prevent silent misconfiguration.
Tool Harness Findings
- File reads and grep searches confirm the implementation matches the diff and integrates cleanly with existing scheduler dependencies.
- CI status confirms all required checks passed for commit
67cb1b4.
| for (const job of config.jobs) { | ||
| deps.log(`scheduling "${job.name}" every ${job.intervalMs}ms -> ${job.path}`); | ||
| deps.setTimeout(() => { | ||
| void schedulerHealthCheck(config, deps); |
There was a problem hiding this comment.
Minor (style): schedulerHealthCheck is invoked inside the job configuration loop, triggering one health check per scheduled job at startup; moving it outside the loop would consolidate to a single verification.
Automated finding from AI PR review.
What
Fixes PORT resolution in the in-app scheduler to properly handle empty/whitespace values, and adds a startup health check that verifies the scheduler can reach its own
/api/healthendpoint before arming periodic jobs.Why
The scheduler previously used `env.PORT |…
Fixes #653
Opened by foreman on review GO (workload wl-misospace-dispatch-653).