.vbw-planning/milestones/polish-and-reliability/phases/01-backend-fixes/PLAN-02.md
After a successful manual health check on a degraded source, enqueue a full feed fetch so SourceHealthMonitor can naturally transition the source's health_status.
@app/jobs/source_monitor/source_health_check_job.rb -- perform, broadcast_outcome (lines 9-24)@lib/source_monitor/health/source_health_check.rb -- call, Result struct@app/jobs/source_monitor/fetch_feed_job.rb -- perform(source_id, force: true) bypasses should_run?@lib/source_monitor/health/source_health_monitor.rb -- runs via after_fetch_completed callback@test/jobs/source_monitor/source_health_check_job_test.rb -- 5 existing testsREQ-HC-01: After a successful manual health check on a declining/critical/warning source, trigger re-evaluation.
Decision: Hybrid approach -- enqueue FetchFeedJob.perform_later(source.id, force: true) after successful health check on degraded source. The full fetch creates a real fetch_log, letting SourceHealthMonitor handle status transitions naturally.
Files: app/jobs/source_monitor/source_health_check_job.rb
In the perform method, after broadcast_outcome(source, result) and before result:
trigger_fetch_if_degraded(source, result)
Add private method:
DEGRADED_STATUSES = %w[declining critical warning].freeze
def trigger_fetch_if_degraded(source, result)
return unless result&.success?
return unless DEGRADED_STATUSES.include?(source.health_status.to_s)
SourceMonitor::FetchFeedJob.perform_later(source.id, force: true)
end
This keeps the logic contained in the job. No changes to SourceHealthCheck or SourceHealthMonitor.
Files: test/jobs/source_monitor/source_health_check_job_test.rb
Add tests using assert_enqueued_with and ActiveJob::TestHelper:
"enqueues fetch when health check succeeds on declining source"
health_status: "declining", stub successful HTTP responseperform_enqueued_jobs(only: SourceMonitor::SourceHealthCheckJob)FetchFeedJob enqueued with [source.id, { force: true }]"enqueues fetch when health check succeeds on critical source"
health_status: "critical""enqueues fetch when health check succeeds on warning source"
health_status: "warning""does not enqueue fetch when health check succeeds on healthy source"
health_status: "healthy", stub successful responseFetchFeedJob enqueued"does not enqueue fetch when health check fails on degraded source"
health_status: "declining", stub timeoutFetchFeedJob enqueued| Action | Path |
|---|---|
| MODIFY | app/jobs/source_monitor/source_health_check_job.rb |
| MODIFY | test/jobs/source_monitor/source_health_check_job_test.rb |
bin/rails test test/jobs/source_monitor/source_health_check_job_test.rb
bin/rubocop app/jobs/source_monitor/source_health_check_job.rb