Class: QueuePulse::Alert

Inherits:
Object
  • Object
show all
Defined in:
lib/queue_pulse/alert.rb

Overview

An immutable description of something worth notifying about.

fingerprint is the dedupe/cooldown key: alerts sharing a fingerprint are considered "the same ongoing condition" and are rate-limited together.

Constant Summary collapse

SEVERITIES =
%i[info warning critical].freeze
SEVERITY_EMOJI =
{ info: "🔵", warning: "🟠", critical: "🔴" }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, severity:, title:, message:, fingerprint:, context: {}) ⇒ Alert

Returns a new instance of Alert.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/queue_pulse/alert.rb', line 13

def initialize(type:, severity:, title:, message:, fingerprint:, context: {})
  @type = type.to_sym
  @severity = severity.to_sym
  unless SEVERITIES.include?(@severity)
    raise ArgumentError, "severity must be one of #{SEVERITIES.inspect}"
  end

  @title = title
  @message = message
  @context = context.freeze
  @fingerprint = fingerprint
  freeze
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



11
12
13
# File 'lib/queue_pulse/alert.rb', line 11

def context
  @context
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



11
12
13
# File 'lib/queue_pulse/alert.rb', line 11

def fingerprint
  @fingerprint
end

#messageObject (readonly)

Returns the value of attribute message.



11
12
13
# File 'lib/queue_pulse/alert.rb', line 11

def message
  @message
end

#severityObject (readonly)

Returns the value of attribute severity.



11
12
13
# File 'lib/queue_pulse/alert.rb', line 11

def severity
  @severity
end

#titleObject (readonly)

Returns the value of attribute title.



11
12
13
# File 'lib/queue_pulse/alert.rb', line 11

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/queue_pulse/alert.rb', line 11

def type
  @type
end

Instance Method Details

#emojiObject



40
41
42
# File 'lib/queue_pulse/alert.rb', line 40

def emoji
  SEVERITY_EMOJI.fetch(severity, "⚪️")
end

#to_hObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/queue_pulse/alert.rb', line 27

def to_h
  {
    type: type,
    severity: severity,
    title: title,
    message: message,
    context: context,
    fingerprint: fingerprint
  }
end