Class: Webhookdb::Organization::Alerting
- Inherits:
-
Object
- Object
- Webhookdb::Organization::Alerting
- Includes:
- Appydays::Configurable
- Defined in:
- lib/webhookdb/organization/alerting.rb
Instance Attribute Summary collapse
-
#org ⇒ Object
readonly
Returns the value of attribute org.
Instance Method Summary collapse
-
#dispatch_alert(message_template) ⇒ Object
Dispatch the message template to administrators of the org.
-
#initialize(org) ⇒ Alerting
constructor
A new instance of Alerting.
Constructor Details
#initialize(org) ⇒ Alerting
Returns a new instance of Alerting.
20 21 22 |
# File 'lib/webhookdb/organization/alerting.rb', line 20 def initialize(org) @org = org end |
Instance Attribute Details
#org ⇒ Object (readonly)
Returns the value of attribute org.
18 19 20 |
# File 'lib/webhookdb/organization/alerting.rb', line 18 def org @org end |
Instance Method Details
#dispatch_alert(message_template) ⇒ Object
Dispatch the message template to administrators of the org.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/webhookdb/organization/alerting.rb', line 26 def dispatch_alert() unless .respond_to?(:signature) raise Webhookdb::InvalidPrecondition, "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 = .signature max_alerts_per_customer_per_day = Webhookdb::Organization::Alerting.max_alerts_per_customer_per_day yesterday = Time.now - 24.hours self.org.admin_customers.each do |c| idemkey = "orgalert-#{signature}-#{c.id}" Webhookdb::Idempotency.every(Webhookdb::Organization::Alerting.interval).under_key(idemkey) do sent_last_day = Webhookdb::Message::Delivery. where(template: .full_template_name, recipient: c). where { created_at > yesterday }. limit(max_alerts_per_customer_per_day). count next unless sent_last_day < max_alerts_per_customer_per_day .dispatch_email(c) end end end |