-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress circuit_success for proxy circuits
- Loading branch information
1 parent
dacba56
commit 0577a53
Showing
7 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
class Faulty | ||
module Events | ||
# Wraps a Notifier and filters events by name | ||
class FilterNotifier | ||
# @param notifier [Notifier] The internal notifier to filter events for | ||
# @param events [Array, nil] An array of events to allow. If nil, all | ||
# {EVENTS} will be used | ||
# @param exclude [Array, nil] An array of events to disallow. If nil, | ||
# no events will be disallowed. Takes priority over `events`. | ||
def initialize(notifier, events: nil, exclude: nil) | ||
@notifier = notifier | ||
@events = Set.new(events || EVENTS) | ||
exclude&.each { |e| @events.delete(e) } | ||
end | ||
|
||
# Notify all listeners of an event | ||
# | ||
# If a listener raises an error while handling an event, that error will | ||
# be captured and written to STDERR. | ||
# | ||
# @param (see Notifier) | ||
def notify(event, payload) | ||
return unless @events.include?(event) | ||
|
||
@notifier.notify(event, payload) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Faulty::Events::FilterNotifier do | ||
let(:backend) { Faulty::Events::Notifier.new } | ||
|
||
it 'forwards all events by default' do | ||
filter = described_class.new(backend) | ||
expect(backend).to receive(:notify).with(:circuit_success, {}) | ||
filter.notify(:circuit_success, {}) | ||
end | ||
|
||
it 'forwards only given events' do | ||
filter = described_class.new(backend, events: %i[circuit_failure]) | ||
expect(backend).to receive(:notify).with(:circuit_failure, {}) | ||
filter.notify(:circuit_success, {}) | ||
filter.notify(:circuit_failure, {}) | ||
end | ||
|
||
it 'forwards all except exluded events' do | ||
filter = described_class.new(backend, exclude: %i[circuit_success]) | ||
expect(backend).to receive(:notify).with(:circuit_failure, {}) | ||
filter.notify(:circuit_success, {}) | ||
filter.notify(:circuit_failure, {}) | ||
end | ||
|
||
it 'forwards given events except excluded' do | ||
filter = described_class.new(backend, events: %i[circuit_failure circuit_success], exclude: %i[circuit_success]) | ||
expect(backend).to receive(:notify).with(:circuit_failure, {}) | ||
filter.notify(:circuit_success, {}) | ||
filter.notify(:circuit_failure, {}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters