Infuse
Infuse is a Python implementation of the Circuit Breaker pattern, described in Michael T. Nygard’s book Release It!.
In Nygard’s words, “circuit breakers exists to allow one subsystem to fail without destroying the entire system. This is done by wrapping dangerous operations (typically integration points) with a component that can circumvent calls when the system is not healthy”.
This basically extends pybreaker with support for Insanic. For full documentation refer to pybreaker. What is different from pybreaker is that it is an asynchronous implementation with asynchronous storage options.
We needed a lot more customizations compared to what the pybreaker was providing. Especially with async storage options. The whole CircuitBreaker implementation needed to be fixed for asyncio support.
Whats up with the name?
Some people might ask why infuse? My basic thought process:
Need a name that starts with “in~”
“Circuit Breaker” -> Fuse box
infuse?
Features
pybreaker features +
aioredis backed storage option
Requirements
Installation
Run the following command line to download the latest stable version of infuse from PyPI
$ pip install insanic-infuse
Usage
Usage of Infuse is different from pybreaker, where everything is done
through the Infuse init_app method.
from insanic import Insanic
from infuse import Infuse
app = Insanic("example", version="0.1.0")
Infuse.init_app(app)
But, before we go on some explanation of what a circuit breaker does:
What Does a Circuit Breaker Do? (from pybreaker)
Let’s say you want to use a circuit breaker on a function that updates a row in the customer database table.
def update_customer(cust):
# Do stuff here...
pass
# Will trigger the circuit breaker
updated_customer = await db_breaker.call(update_customer, my_customer)
According to the default parameters, the circuit breaker db_breaker will
automatically OPEN the circuit after 5 consecutive failures in
update_customer.
When the circuit is OPEN, all calls to update_customer will fail immediately
(raising a CircuitBreakerError) without any attempt to execute the real
operation.
After 60 seconds, the circuit breaker will allow the next call to
update_customer pass through. This state is called HALF OPEN .
If that call succeeds, the circuit is CLOSED ;
if it fails, however, the circuit is OPEN ed again until another timeout elapses.
Excluding Exceptions(from pybreaker)
By default, a failed call is any call that raises an exception. However, it’s common to raise exceptions to also indicate business exceptions, and those exceptions should be ignored by the circuit breaker as they don’t indicate system errors.
# At creation time...
db_breaker = CircuitBreaker(exclude=[CustomerValidationError])
# ...or later
db_breaker.add_excluded_exception(CustomerValidationError)
In that case, when any function guarded by that circuit breaker raises
CustomerValidationError (or any exception derived from
CustomerValidationError), that call won’t be considered a system failure.
What does Infuse do?
Infuse, when initializing the Insanic application
Sets its own state on the storage as defined in
INFUSE_INITIAL_CIRCUIT_STATE.Patches Insanic’s Service object to wrap with circuit breaking.
Other than this, there are some configurations you can tweak. Pretty simple.
For more information, please refer to the Documentation.
Release History
View release history here
Contributing
For guidance on setting up a development environment and how to make a contribution to Infuse, see the CONTRIBUTING.rst guidelines.
Meta
Distributed under the MIT license. See LICENSE for more information.
Thanks to all the people at my prior company that worked with me to make this possible.
Links
Documentation: https://infuse.readthedocs.io/en/latest/
Releases: https://pypi.org/project/insanic-infuse/
Issue Tracker: https://www.github.com/crazytruth/infuse/issues
Insanic Documentation: http://insanic.readthedocs.io/
Insanic Repository: https://www.github.com/crazytruth/insanic/
Metadata
Release files for insanic-infuse 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| insanic-infuse-0.4.0.tar.gz | 31.6 kB | Without provenance | Details for insanic-infuse-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| insanic_infuse-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for insanic_infuse-0.4.0-py3-none-any.whl |
Total release size: 46.6 kB
Release files / insanic-infuse-0.4.0.tar.gz
| Download URL | insanic-infuse-0.4.0.tar.gz |
|---|---|
| Size | 31.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d7683d3ba89b2fb01c98e7a6050a64038002bcfec8ac4f0853c64a681850147
|
|
BLAKE2b-256 checksum How to use checksums |
74d2a68a23de722369f9241d4904994b1274526c9f4972912893c809014aa904
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.1
|
Release files / insanic_infuse-0.4.0-py3-none-any.whl
| Download URL | insanic_infuse-0.4.0-py3-none-any.whl |
|---|---|
| Size | 15.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d3a76f0af7af96e322f572dac993a12622f663993edd0085822a124eb01621f
|
|
BLAKE2b-256 checksum How to use checksums |
a736685bf2abb5f85d056a004a6309959d2a73ebe40a36cafb6018306381c3ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.1
|
Security for insanic-infuse 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.