execution_service ¶
Execution service for moderation operations.
Handles retry logic, circuit breakers, and execution management using proper service composition.
Classes:
-
ExecutionService–Service for executing moderation actions with retry logic.
Classes¶
ExecutionService ¶
ExecutionService(
failure_threshold: int = 5,
recovery_timeout: float = 60.0,
max_retries: int = 3,
base_delay: float = 1.0,
)
Service for executing moderation actions with retry logic.
Provides circuit breaker patterns and proper error handling for Discord API operations.
Initialize the execution service.
Parameters:
-
failure_threshold(int, default:5) –Number of failures before opening circuit breaker, by default 5.
-
recovery_timeout(float, default:60.0) –Seconds to wait before retrying after circuit opens, by default 60.0.
-
max_retries(int, default:3) –Maximum number of retry attempts for operations, by default 3.
-
base_delay(float, default:1.0) –Base delay in seconds for exponential backoff, by default 1.0.
Methods:
-
execute_with_retry–Execute an action with retry logic and circuit breaker.
-
get_operation_type–Get the operation type for circuit breaker based on case type.
Functions¶
execute_with_retry async ¶
execute_with_retry(
operation_type: str,
action: Callable[..., Coroutine[Any, Any, Any]],
*args: Any,
**kwargs: Any,
) -> Any
Execute an action with retry logic and circuit breaker.
Parameters:
-
operation_type(str) –Type of operation for circuit breaker.
-
action(Callable[..., Coroutine[Any, Any, Any]]) –The async callable to execute (must be a callable, not a coroutine).
-
*args(Any, default:()) –Positional arguments for the action.
-
**kwargs(Any, default:{}) –Keyword arguments for the action.
Returns:
-
Any–The result of the action.
Raises:
-
RuntimeError–If the circuit breaker is open for this operation type.
-
Forbidden–If the bot lacks permissions.
-
HTTPException–If a Discord API error occurs.
-
NotFound–If the resource is not found.
_is_circuit_open ¶
_calculate_delay ¶
get_operation_type ¶
Get the operation type for circuit breaker based on case type.
Uses the case type name directly as the operation type for simplicity and clear correlation between operations and their failure patterns.
Parameters:
-
case_type(CaseType) –The case type.
Returns:
-
str–Operation type string for circuit breaker configuration.