Class: Webhookdb::Organization::Alerting

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(org) ⇒ Alerting

Returns a new instance of Alerting.



15
16
17
# File 'lib/webhookdb/organization/alerting.rb', line 15

def initialize(org)
  @org = org
end

Instance Attribute Details

#orgObject (readonly)

Returns the value of attribute org.



13
14
15
# File 'lib/webhookdb/organization/alerting.rb', line 13

def org
  @org
end

Instance Method Details

#dispatch_alert(message_template) ⇒ Object

Dispatch the message template to administrators of the org.

Parameters:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/webhookdb/organization/alerting.rb', line 21

def dispatch_alert(message_template)
  unless message_template.respond_to?(:signature)
    raise Webhookdb::InvalidPrecondition,
          "message template #{message_template.template_name} must define a #signature method, " \
          "which is a unique identity for this error type, used for grouping and idempotency"
  end
  signature = message_template.signature
  self.org.admin_customers.each do |c|
    idemkey = "orgalert-#{signature}-#{c.id}"
    Webhookdb::Idempotency.every(Webhookdb::Organization::Alerting.interval).under_key(idemkey) do
      message_template.dispatch_email(c)
    end
  end
end