Skip to content

Register functions with full names (including modules)#68

Open
yarjor wants to merge 1 commit intofabfuel:developfrom
yarjor:monitor-full-names
Open

Register functions with full names (including modules)#68
yarjor wants to merge 1 commit intofabfuel:developfrom
yarjor:monitor-full-names

Conversation

@yarjor
Copy link
Copy Markdown
Contributor

@yarjor yarjor commented Apr 4, 2025

partly fix #56 , review issue for reasoning behind the behavior change.
New behavior when decorating 2 functions from different modules with unnamed circuitbreakers will be:

# example_a.py
@circuit(failure_threshold=3, recovery_timeout=5)
def func():
    return 42
# example_b.py
@circuit(failure_threshold=3, recovery_timeout=5)
def func():
    raise Exception()
# example.py
import example_a
import example_b

# Now, CircuitBreakerMonitor should look like this:
> {
>    "func" : example_b.func,  # last defined circuitbreaker
>    "example_a.func" : example_a.func,
>    "example_b.func" : example_b.func
> }

@fabfuel
Copy link
Copy Markdown
Owner

fabfuel commented Apr 7, 2025

Thanks for the PR @yarjor!

That's certainly a good, pragmatic change, but I would prefer to have the deduplication happening once, on registration of a new Circuitbreaker instead of every time on read.
Especially when we want to fix the original issue, that we do not overwrite breakers with the same name and we need to add some logic to keep them identifiable.

What do you think about keeping cls.circuit_breakers as is and create an additional new lookup dict, that we can use in e.g. get() to get a circuitbreaker by either the simple (old) name or via module.name?

Best
Fabian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Circuit breaker overriding with same name in CircuitBreakerMonitor

2 participants