Class: Stoplight::Infrastructure::Notifier::FailSafe Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight/infrastructure/notifier/fail_safe.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A wrapper around a notifier that provides fail-safe mechanisms using a circuit breaker. It ensures that a notification can gracefully handle failures.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notifier:, error_notifier:) ⇒ FailSafe

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FailSafe.

Parameters:

  • notifier

    The notifier to wrap.

  • error_notifier

    called when wrapped data store fails



19
20
21
22
# File 'lib/stoplight/infrastructure/notifier/fail_safe.rb', line 19

def initialize(notifier:, error_notifier:)
  @notifier = notifier
  @error_notifier = error_notifier
end

Instance Attribute Details

#error_notifierObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The underlying notifier being wrapped.



15
16
17
# File 'lib/stoplight/infrastructure/notifier/fail_safe.rb', line 15

def error_notifier
  @error_notifier
end

#notifierObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The underlying notifier being wrapped.



13
14
15
# File 'lib/stoplight/infrastructure/notifier/fail_safe.rb', line 13

def notifier
  @notifier
end

Instance Method Details

#==(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


37
38
39
# File 'lib/stoplight/infrastructure/notifier/fail_safe.rb', line 37

def ==(other)
  other.is_a?(self.class) && notifier == other.notifier
end

#notify(info, from_color, to_color, error = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sends a notification using the wrapped notifier with fail-safe mechanisms.



25
26
27
28
29
30
31
32
33
34
# File 'lib/stoplight/infrastructure/notifier/fail_safe.rb', line 25

def notify(info, from_color, to_color, error = nil)
  fallback = proc do |exception|
    error_notifier.call(exception) if exception
    nil
  end #: ^(StandardError?) -> void

  circuit_breaker.run(fallback) do
    notifier.notify(info, from_color, to_color, error)
  end #: void
end