Class: SolidEvents::Incident

Inherits:
Record
  • Object
show all
Defined in:
app/models/solid_events/incident.rb

Constant Summary collapse

STATUSES =
%w[active acknowledged resolved].freeze

Instance Method Summary collapse

Instance Method Details

#acknowledge!Object



18
19
20
21
# File 'app/models/solid_events/incident.rb', line 18

def acknowledge!
  update!(status: "acknowledged", acknowledged_at: Time.current)
  record_event!(action: "acknowledged", payload: {status: "acknowledged"})
end

#assign!(owner:, team: nil, assigned_by: nil, assignment_note: nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'app/models/solid_events/incident.rb', line 38

def assign!(owner:, team: nil, assigned_by: nil, assignment_note: nil)
  update!(
    owner: owner,
    team: team,
    assigned_by: assigned_by,
    assignment_note: assignment_note,
    assigned_at: Time.current
  )
  record_event!(action: "assigned", actor: assigned_by, payload: {owner: owner, team: team, assignment_note: assignment_note})
end

#mute_for!(duration) ⇒ Object



33
34
35
36
# File 'app/models/solid_events/incident.rb', line 33

def mute_for!(duration)
  update!(muted_until: duration.from_now)
  record_event!(action: "muted", payload: {muted_until: muted_until})
end

#record_event!(action:, actor: nil, payload: {}) ⇒ Object



59
60
61
62
63
64
65
66
# File 'app/models/solid_events/incident.rb', line 59

def record_event!(action:, actor: nil, payload: {})
  incident_events.create!(
    action: action,
    actor: actor,
    payload: payload,
    occurred_at: Time.current
  )
end

#reopen!Object



28
29
30
31
# File 'app/models/solid_events/incident.rb', line 28

def reopen!
  update!(status: "active", resolved_at: nil, resolved_by: nil, resolution_note: nil)
  record_event!(action: "reopened", payload: {status: "active"})
end

#resolve!Object



23
24
25
26
# File 'app/models/solid_events/incident.rb', line 23

def resolve!
  update!(status: "resolved", resolved_at: Time.current)
  record_event!(action: "resolved", payload: {status: "resolved"})
end

#resolve_with!(resolved_by:, resolution_note: nil) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'app/models/solid_events/incident.rb', line 49

def resolve_with!(resolved_by:, resolution_note: nil)
  update!(
    status: "resolved",
    resolved_at: Time.current,
    resolved_by: resolved_by,
    resolution_note: resolution_note
  )
  record_event!(action: "resolved", actor: resolved_by, payload: {resolution_note: resolution_note})
end