Class: Webhookdb::DeveloperAlert

Inherits:
Object
  • Object
show all
Includes:
Appydays::Configurable
Defined in:
lib/webhookdb/developer_alert.rb

Overview

Decouples the need to alert from the way we want to handle alerts. This is for something in between purely technical alerts (error handling in Sentry) and ops/marketing alerts (which may post to Slack or whatever). Instead of having to rewrite many async jobs to not use Slack, we can just modiy the one job that handles developer alerts.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subsystem:, emoji:, fallback:, fields:) ⇒ DeveloperAlert

Returns a new instance of DeveloperAlert.



16
17
18
19
20
21
# File 'lib/webhookdb/developer_alert.rb', line 16

def initialize(subsystem:, emoji:, fallback:, fields:)
  @subsystem = subsystem
  @emoji = emoji
  @fallback = fallback
  @fields = fields
end

Instance Attribute Details

#emojiObject

Returns the value of attribute emoji.



14
15
16
# File 'lib/webhookdb/developer_alert.rb', line 14

def emoji
  @emoji
end

#fallbackObject

Returns the value of attribute fallback.



14
15
16
# File 'lib/webhookdb/developer_alert.rb', line 14

def fallback
  @fallback
end

#fieldsObject

Returns the value of attribute fields.



14
15
16
# File 'lib/webhookdb/developer_alert.rb', line 14

def fields
  @fields
end

#subsystemObject

Returns the value of attribute subsystem.



14
15
16
# File 'lib/webhookdb/developer_alert.rb', line 14

def subsystem
  @subsystem
end

Instance Method Details

#as_jsonObject



23
24
25
26
27
28
29
30
# File 'lib/webhookdb/developer_alert.rb', line 23

def as_json
  return {
    subsystem:,
    emoji:,
    fallback:,
    fields:,
  }
end

#emitObject



32
33
34
# File 'lib/webhookdb/developer_alert.rb', line 32

def emit
  Amigo.publish("webhookdb.developeralert.emitted", self.as_json)
end

#handleObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/webhookdb/developer_alert.rb', line 36

def handle
  notifier = Webhookdb::Slack.new_notifier(
    channel: "#webhookdb-notifications",
    username: @subsystem,
    icon_emoji: @emoji,
  )
  notifier.post(
    attachments: [
      {
        fallback: @fallback,
        fields: @fields,
      },
    ],
  )
end