Supervision¶
casty.SupervisionStrategy
¶
Bases: Protocol
Protocol for deciding how to handle actor failures.
Implementations receive the exception raised by a child actor and
return a Directive indicating the recovery action.
Examples:
>>> class AlwaysRestart:
... def decide(self, exception, *, child_id="", **kw):
... return Directive.restart
decide(exception, *, child_id=..., **kwargs)
¶
casty.OneForOneStrategy
¶
Bases: SupervisionStrategy
Supervision strategy that handles each child failure independently.
Restarts a failing child up to max_restarts times within a
sliding time window. If the limit is exceeded the child is stopped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_restarts
|
int
|
Maximum number of restarts allowed within the time window. |
3
|
within
|
float
|
Length of the sliding time window in seconds. |
60.0
|
decider
|
Callable[[Exception], Directive] | None
|
Optional function to override the directive for specific
exceptions. If it returns |
None
|
Examples:
>>> from casty import OneForOneStrategy, Directive
>>> strategy = OneForOneStrategy(max_restarts=5, within=30.0)
__init__(max_restarts=3, within=60.0, decider=None)
¶
decide(exception, *, child_id='__default__', **kwargs)
¶
Decide the recovery action for a failed child actor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exception
|
Exception
|
The exception that caused the child to fail. |
required |
child_id
|
str
|
Identifier for the child actor, used to track per-child restart frequency. |
'__default__'
|
Returns:
| Type | Description |
|---|---|
Directive
|
The action to take: restart, stop, or escalate. |
Examples:
casty.Directive
¶
Bases: Enum
Action to take when a supervised actor fails.
Examples: