Module: SourceMonitor::HealthBadgeHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/source_monitor/health_badge_helper.rb

Instance Method Summary collapse

Instance Method Details

#interactive_health_status?(source, override: nil) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
# File 'app/helpers/source_monitor/health_badge_helper.rb', line 58

def interactive_health_status?(source, override: nil)
  return false if override.present?

  %w[failing declining].include?(source&.health_status.presence)
end

#source_health_actions(source) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/source_monitor/health_badge_helper.rb', line 21

def source_health_actions(source)
  status = source&.health_status.presence || "working"
  helpers = SourceMonitor::Engine.routes.url_helpers

  case status
  when "failing", "declining"
    [
      {
        key: :full_fetch,
        label: "Queue Full Fetch",
        description: "Runs the full fetch pipeline immediately and updates items if the feed responds.",
        path: helpers.source_fetch_path(source),
        method: :post,
        data: { testid: "source-health-action-full_fetch" }
      },
      {
        key: :health_check,
        label: "Run Health Check",
        description: "Sends a single request to confirm the feed is reachable without modifying stored items.",
        path: helpers.source_health_check_path(source),
        method: :post,
        data: { testid: "source-health-action-health_check" }
      },
      {
        key: :reset,
        label: "Reset to Active Status",
        description: "Clears failure count, backoff timers, and auto-pause state so the source resumes normal fetching.",
        path: helpers.source_health_reset_path(source),
        method: :post,
        data: { testid: "source-health-action-reset" }
      }
    ]
  else
    []
  end
end

#source_health_badge(source, override: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/source_monitor/health_badge_helper.rb', line 5

def source_health_badge(source, override: nil)
  return override if override.present?

  status = source&.health_status.presence || "working"

  mapping = {
    "working" => { label: "Working", classes: "bg-green-100 text-green-700", show_spinner: false },
    "declining" => { label: "Declining", classes: "bg-yellow-100 text-yellow-700", show_spinner: false },
    "improving" => { label: "Improving", classes: "bg-sky-100 text-sky-700", show_spinner: false },
    "failing" => { label: "Failing", classes: "bg-rose-100 text-rose-700", show_spinner: false },
    "unknown" => { label: "Unknown", classes: "bg-slate-100 text-slate-600", show_spinner: false }
  }

  mapping.fetch(status) { mapping.fetch("unknown") }.merge(status: status)
end