Class: Faulty::Scope
- Inherits:
-
Object
- Object
- Faulty::Scope
- Defined in:
- lib/faulty/scope.rb
Overview
A Scope is a group of options and circuits
For most use-cases the default scope should be used, however, it's possible to create any number of scopes for applications that require a more complex configuration or for testing.
For the most part, scopes are independent, however for some cache and storage backends, you will need to ensure that the cache keys and circuit names don't overlap between scopes. For example, if using the Redis storage backend, you should specify different key prefixes for each scope.
Defined Under Namespace
Classes: Options
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#circuit(name, **options) {|Circuit::Options| ... } ⇒ Circuit
Create or retrieve a circuit.
-
#initialize(**options) {|Options| ... } ⇒ Scope
constructor
Create a new Faulty Scope.
-
#list_circuits ⇒ Array<String>
Get a list of all circuit names.
Constructor Details
#initialize(**options) {|Options| ... } ⇒ Scope
Create a new Faulty Scope
Note, the process of creating a new scope is not thread safe, so make sure scopes are setup before spawning threads.
75 76 77 78 |
# File 'lib/faulty/scope.rb', line 75 def initialize(**, &block) @circuits = Concurrent::Map.new @options = Options.new(, &block) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/faulty/scope.rb', line 15 def @options end |
Instance Method Details
#circuit(name, **options) {|Circuit::Options| ... } ⇒ Circuit
Create or retrieve a circuit
Within a scope, circuit instances have unique names, so if the given circuit name already exists, then the existing circuit will be returned, otherwise a new circuit will be created. If an existing circuit is returned, then the #options param and block are ignored.
91 92 93 94 95 96 97 |
# File 'lib/faulty/scope.rb', line 91 def circuit(name, **, &block) name = name.to_s = .merge() @circuits.compute_if_absent(name) do Circuit.new(name, **, &block) end end |
#list_circuits ⇒ Array<String>
Get a list of all circuit names
102 103 104 |
# File 'lib/faulty/scope.rb', line 102 def list_circuits .storage.list end |