Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce circuit breaker manager #86

Open
roma-glushko opened this issue Oct 5, 2023 · 0 comments
Open

Introduce circuit breaker manager #86

roma-glushko opened this issue Oct 5, 2023 · 0 comments

Comments

@roma-glushko
Copy link
Owner

roma-glushko commented Oct 5, 2023

As brought up in #85, I would be great to have a single component that manages seamlessly all breakers in the service.

The manager could be defined somewhere as a singleton and passed around the places (via dependency injection, for example):

from typing import Any

import httpx


class CurrencyRate:
    ...


class CurrencyRates:
    def __init__(self, breaker_manager: CircuitBreakerManager) -> None:
        self._breaker_manager = breaker_manager

    async def get_rates(self) -> list[CurrencyRate]:
        with self.breaker_manager("currency.rates", exceptions=(httpx.NetworkError,)):  # manager creates/retrieves and activates breaker
            async with httpx.AsyncClient() as client:
                response = await client.get("https://api.github.com/events")

                return self._map_rates(response.json())

    def _map_rates(self, data: list[dict[str, Any]]) -> list[CurrencyRate]:
        ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant