Module: Faulty::Patch
- Defined in:
- lib/faulty/patch.rb,
lib/faulty/patch/base.rb,
lib/faulty/patch/redis.rb,
lib/faulty/patch/mysql2.rb,
lib/faulty/patch/redis/patch.rb,
lib/faulty/patch/elasticsearch.rb,
lib/faulty/patch/redis/middleware.rb
Overview
Automatic wrappers for common core dependencies like database connections or caches
Defined Under Namespace
Modules: Base, Elasticsearch, Mysql2, Redis
Class Method Summary collapse
-
.circuit_from_hash(default_name, hash, **options) {|Circuit::Options| ... } ⇒ Circuit?
Create a circuit from a configuration hash.
-
.define_circuit_errors(namespace, base) ⇒ void
Create a full set of CircuitErrors with a given base error class.
Class Method Details
.circuit_from_hash(default_name, hash, **options) {|Circuit::Options| ... } ⇒ Circuit?
Create a circuit from a configuration hash
This is intended to be used in contexts where the user passes in
something like a connection hash to a third-party library. For example
the Redis patch hooks into the normal Redis connection options to add
a :faulty
key, which is a hash of faulty circuit options. This is
slightly different from the normal Faulty circuit options because
we also accept an :instance
key which is a faulty instance.
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/faulty/patch.rb', line 78 def circuit_from_hash(default_name, hash, **, &block) return unless hash hash = symbolize_keys(hash) name = hash.delete(:name) || default_name patch_errors = hash.delete(:patch_errors) != false error_mapper = .delete(:patched_error_mapper) hash[:error_mapper] ||= error_mapper if error_mapper && patch_errors faulty = resolve_instance(hash.delete(:instance)) faulty.circuit(name, **hash, **, &block) end |
.define_circuit_errors(namespace, base) ⇒ void
This method returns an undefined value.
Create a full set of CircuitErrors with a given base error class
For patches that need their errors to be subclasses of a common base.
97 98 99 100 101 102 103 |
# File 'lib/faulty/patch.rb', line 97 def define_circuit_errors(namespace, base) circuit_error = Class.new(base) { include CircuitErrorBase } namespace.const_set('CircuitError', circuit_error) namespace.const_set('OpenCircuitError', Class.new(circuit_error)) namespace.const_set('CircuitFailureError', Class.new(circuit_error)) namespace.const_set('CircuitTrippedError', Class.new(circuit_error)) end |