Files
MatchLiveTv/backend/app/models/ops/incident.rb
Emiliano Frascaro a44d9fbadd HLS su edge e monitoraggio ops con latenza p95.
Evita di saturare Puma in diretta, separa i check Rails/pubblico e traccia la latenza /up per alert più affidabili.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-14 21:19:32 +02:00

44 lines
1.3 KiB
Ruby

module Ops
class Incident < ApplicationRecord
self.table_name = "ops_incidents"
KINDS = %w[
disk_space recordings_size service_down http_public http_rails rails_latency
sidekiq_stale sidekiq_dead log_pattern garage_storage
].freeze
SEVERITIES = %w[critical warning info].freeze
STATUSES = %w[open acknowledged resolved].freeze
validates :kind, :severity, :status, :title, :fingerprint, presence: true
validates :severity, inclusion: { in: SEVERITIES }
validates :status, inclusion: { in: STATUSES }
validates :occurrence_count, numericality: { greater_than: 0 }
scope :open, -> { where(status: %w[open acknowledged]) }
scope :unresolved, -> { where.not(status: "resolved") }
scope :critical_open, -> { open.where(severity: "critical") }
scope :recent, -> { order(last_seen_at: :desc) }
scope :since, ->(time) { where("last_seen_at >= ?", time) }
def open?
status.in?(%w[open acknowledged])
end
def muted?
muted_until.present? && muted_until.future?
end
def acknowledge!
update!(status: "acknowledged", acknowledged_at: Time.current)
end
def resolve!
update!(status: "resolved")
end
def mute!(duration: 24.hours)
update!(muted_until: duration.from_now)
end
end
end