lib/circuitbox/notifier.rb in circuitbox-0.5.2 vs lib/circuitbox/notifier.rb in circuitbox-0.7.0
- old
+ new
@@ -1,12 +1,34 @@
class Circuitbox
class Notifier
- def self.notify(event, service, partition = nil)
- return unless defined? ActiveSupport::Notifications
+ def initialize(service, partition=nil)
+ @service = service
+ @partition = partition
+ end
- circuit_name = service
- circuit_name += ":#{partition}" if partition
-
+ def notify(event)
+ return unless notification_available?
ActiveSupport::Notifications.instrument("circuit_#{event}", circuit: circuit_name)
end
+
+ def notify_warning(message)
+ return unless notification_available?
+ ActiveSupport::Notifications.instrument("circuit_warning", { circuit: circuit_name, message: message})
+ end
+
+ def metric_gauge(gauge, value)
+ return unless notification_available?
+ ActiveSupport::Notifications.instrument("circuit_gauge", { circuit: circuit_name, gauge: gauge.to_s, value: value })
+ end
+
+ private
+ def circuit_name
+ circuit_name = @service.to_s
+ circuit_name += ":#{@partition}" if @partition
+ circuit_name
+ end
+
+ def notification_available?
+ defined? ActiveSupport::Notifications
+ end
end
-end
\ No newline at end of file
+end