Module: Faulty
- Defined in:
- lib/faulty.rb,
lib/faulty/cache.rb,
lib/faulty/error.rb,
lib/faulty/scope.rb,
lib/faulty/events.rb,
lib/faulty/result.rb,
lib/faulty/status.rb,
lib/faulty/circuit.rb,
lib/faulty/storage.rb,
lib/faulty/version.rb,
lib/faulty/cache/mock.rb,
lib/faulty/cache/null.rb,
lib/faulty/cache/rails.rb,
lib/faulty/cache/default.rb,
lib/faulty/storage/redis.rb,
lib/faulty/storage/memory.rb,
lib/faulty/cache/interface.rb,
lib/faulty/events/notifier.rb,
lib/faulty/immutable_options.rb,
lib/faulty/storage/interface.rb,
lib/faulty/events/log_listener.rb,
lib/faulty/events/callback_listener.rb,
lib/faulty/events/listener_interface.rb,
lib/faulty/cache/fault_tolerant_proxy.rb,
lib/faulty/events/honeybadger_listener.rb,
lib/faulty/storage/fault_tolerant_proxy.rb
Overview
The top-level namespace for Faulty
Fault-tolerance tools for ruby based on circuit-breakers
Defined Under Namespace
Modules: Cache, Events, ImmutableOptions, Storage Classes: AlreadyInitializedError, Circuit, CircuitError, CircuitFailureError, CircuitTrippedError, FaultyError, MissingDefaultScopeError, OpenCircuitError, Result, Scope, Status, UncheckedResultError, UninitializedError, WrongResultError
Class Method Summary collapse
-
.[](scope_name) ⇒ Scope?
Get a scope by name.
-
.circuit(name, **config) {|Circuit::Options| ... } ⇒ Circuit
Get or create a circuit for the default scope.
-
.current_time ⇒ Time
The current time.
-
.default ⇒ Scope?
Get the default scope given during Faulty.init.
-
.init(scope_name = :default, **config) {|Scope::Options| ... } ⇒ self
Start the Faulty environment.
-
.list_circuits ⇒ Array<String>
Get a list of all circuit names for the default scope.
-
.options ⇒ Scope::Options
Get the options for the default scope.
-
.register(name, scope) ⇒ Scope?
Register a scope to the global Faulty state.
-
.version ⇒ Object
The current Faulty version.
Class Method Details
.[](scope_name) ⇒ Scope?
Get a scope by name
62 63 64 65 66 |
# File 'lib/faulty.rb', line 62 def [](scope_name) raise UninitializedError unless @scopes @scopes[scope_name] end |
.circuit(name, **config) {|Circuit::Options| ... } ⇒ Circuit
Get or create a circuit for the default scope
97 98 99 |
# File 'lib/faulty.rb', line 97 def circuit(name, **config, &block) default.circuit(name, **config, &block) end |
.current_time ⇒ Time
The current time
Used by Faulty wherever the current time is needed. Can be overridden for testing
114 115 116 |
# File 'lib/faulty.rb', line 114 def current_time Time.now.to_i end |
.default ⇒ Scope?
Get the default scope given during init
52 53 54 55 56 57 |
# File 'lib/faulty.rb', line 52 def default raise UninitializedError unless @scopes raise MissingDefaultScopeError unless @default_scope self[@default_scope] end |
.init(scope_name = :default, **config) {|Scope::Options| ... } ⇒ self
Start the Faulty environment
This creates a global shared Faulty state for configuration and for re-using State objects.
Not thread safe, should be executed before any worker threads are spawned.
If you prefer dependency-injection instead of global state, you can skip init and pass a Scope directly to your dependencies.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/faulty.rb', line 37 def init(scope_name = :default, **config, &block) raise AlreadyInitializedError if @scopes @default_scope = scope_name @scopes = Concurrent::Map.new register(scope_name, Scope.new(**config, &block)) unless scope_name.nil? self rescue StandardError @scopes = nil raise end |
.list_circuits ⇒ Array<String>
Get a list of all circuit names for the default scope
104 105 106 |
# File 'lib/faulty.rb', line 104 def list_circuits .storage.list end |
.options ⇒ Scope::Options
Get the options for the default scope
87 88 89 |
# File 'lib/faulty.rb', line 87 def default. end |
.register(name, scope) ⇒ Scope?
Register a scope to the global Faulty state
Will not replace an existing scope with the same name. Check the return value if you need to know whether the scope already existed.
77 78 79 80 81 |
# File 'lib/faulty.rb', line 77 def register(name, scope) raise UninitializedError unless @scopes @scopes.put_if_absent(name, scope) end |
.version ⇒ Object
The current Faulty version
5 6 7 |
# File 'lib/faulty/version.rb', line 5 def self.version Gem::Version.new('0.1.4') end |