Module: SolidObserver::ApplicationHelper
- Defined in:
- app/helpers/solid_observer/application_helper.rb
Constant Summary collapse
- STATUS_COLORS =
{ "completed" => "success", "ready" => "success", "failed" => "danger", "retry_stopped" => "danger", "scheduled" => "warning", "claimed" => "warning", "enqueued" => "info", "discarded" => "info" }.freeze
- DURATION_SEMANTICS =
{ "job_enqueued" => "Time spent in the ActiveJob enqueue call (Rails internal; typically sub-millisecond to single-digit ms)", "job_completed" => "Time spent performing the job", "job_failed" => "Time spent performing the job before the exception was raised", "job_discarded" => "Time before discard decision was made" }.freeze
- STABILITY_STATES =
{ stable: {label: "Stable", tone: "success"}, degraded: {label: "Degraded", tone: "warning"}, critical: {label: "Critical", tone: "danger"} }.freeze
Instance Method Summary collapse
- #duration_with_semantic(value, event_type) ⇒ Object
- #execution_status(execution) ⇒ Object
- #format_duration(seconds) ⇒ Object
- #latest_failure_phrase(timestamp) ⇒ Object
- #mode_badge ⇒ Object
- #stability_badge(stats) ⇒ Object
- #stability_detail(stats) ⇒ Object
- #stability_state(stats) ⇒ Object
- #status_badge(status) ⇒ Object
- #turbo_frame_tag(id, **options, &block) ⇒ Object
Instance Method Details
#duration_with_semantic(value, event_type) ⇒ Object
47 48 49 50 51 |
# File 'app/helpers/solid_observer/application_helper.rb', line 47 def duration_with_semantic(value, event_type) return content_tag(:span, "—", class: "so-text-muted") unless value content_tag(:abbr, format_duration(value), title: DURATION_SEMANTICS.fetch(event_type.to_s)) end |
#execution_status(execution) ⇒ Object
27 28 29 |
# File 'app/helpers/solid_observer/application_helper.rb', line 27 def execution_status(execution) ExecutionPresenter.new(execution).status end |
#format_duration(seconds) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/solid_observer/application_helper.rb', line 31 def format_duration(seconds) return "0ms" if seconds.to_f.zero? if seconds < 1 "#{(seconds * 1000).round}ms" else "#{"%.1f" % seconds}s" end end |
#latest_failure_phrase(timestamp) ⇒ Object
91 92 93 |
# File 'app/helpers/solid_observer/application_helper.rb', line 91 def latest_failure_phrase() ? "#{time_ago_in_words()} ago" : "unknown" end |
#mode_badge ⇒ Object
53 54 55 56 57 |
# File 'app/helpers/solid_observer/application_helper.rb', line 53 def mode_badge config = SolidObserver.config color = config.persistence_mode? ? "info" : "warning" content_tag(:span, config.storage_mode.to_s.capitalize, class: "so-badge so-badge--#{color}") end |
#stability_badge(stats) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'app/helpers/solid_observer/application_helper.rb', line 75 def stability_badge(stats) = STABILITY_STATES.fetch(stability_state(stats)) dot = tag.svg(tag.circle(r: 3, cx: 3, cy: 3), class: "so-badge__dot", viewBox: "0 0 6 6", "aria-hidden": "true") tag.span(class: "so-badge so-badge--pill so-badge--#{[:tone]}") do safe_join([dot, [:label]], " ") end end |
#stability_detail(stats) ⇒ Object
84 85 86 87 88 89 |
# File 'app/helpers/solid_observer/application_helper.rb', line 84 def stability_detail(stats) failures_24h = stats[:failed_last_24h].to_i return "No failures in the last 24h" if failures_24h.zero? "#{pluralize(failures_24h, "failure")} in the last 24h, latest #{latest_failure_phrase(stats[:latest_failure_at])}" end |
#stability_state(stats) ⇒ Object
68 69 70 71 72 73 |
# File 'app/helpers/solid_observer/application_helper.rb', line 68 def stability_state(stats) return :critical if stats[:failed_last_hour].to_i.positive? return :degraded if stats[:failed_last_24h].to_i.positive? :stable end |
#status_badge(status) ⇒ Object
41 42 43 44 45 |
# File 'app/helpers/solid_observer/application_helper.rb', line 41 def status_badge(status) status_str = status.to_s color = STATUS_COLORS.fetch(status_str, "default") content_tag(:span, status_str.humanize, class: "so-badge so-badge--#{color}") end |
#turbo_frame_tag(id, **options, &block) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'app/helpers/solid_observer/application_helper.rb', line 59 def turbo_frame_tag(id, **, &block) return super if defined?(super) content = .delete(:content) body = block_given? ? capture(&block) : content content_tag(:"turbo-frame", body, **.merge(id: id).compact) end |