Class: CodeSunset::AlertDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/code_sunset/alert_dispatcher.rb

Constant Summary collapse

ALERT_KIND =
"deprecated_usage".freeze

Instance Method Summary collapse

Constructor Details

#initialize(feature_key) ⇒ AlertDispatcher

Returns a new instance of AlertDispatcher.



5
6
7
# File 'lib/code_sunset/alert_dispatcher.rb', line 5

def initialize(feature_key)
  @feature = CodeSunset::Feature.find_by(key: feature_key)
end

Instance Method Details

#dispatch_if_due ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/code_sunset/alert_dispatcher.rb', line 9

def dispatch_if_due
  return unless feature

  snapshot = CodeSunset::FeatureQuery.new({}, scope: CodeSunset::Feature.where(id: feature.id)).call.first
  return unless snapshot
  return unless alertable?(snapshot)
  return if recently_delivered?(snapshot)

  payload = build_payload(snapshot)
  notify_logger(payload)
  notify_webhook(payload)
  notify_slack(payload)
  record_delivery(snapshot, payload)
  payload
end