- class ExecutionChain(function_chain=None)[source]
Bases:
object
A class that represents a chain of functions to be executed sequentially.
- Attributes:
- functionsList[Callable]
List of functions to be executed in the chain.
Methods
__call__(**kwargs):
Executes all the functions in the chain.
add_function(function: Callable, position: int = -1):
Adds a function to the chain at a specified position.
remove_function(function: Callable):
Removes a specific function from the chain.
replace_function(old_function: Callable, new_function: Callable):
Replaces a specific function in the chain with a new one.
validate_chain():
Validates the function chain.
- add_function(function, position=- 1)[source]
Adds a function to the chain at a specified position. Default is end of the chain.
- Parameters:
- functionCallable
- positionint, optional
The function to add to the chain.
The position in the chain to add the function to, by default -1 which corresponds to the end of the chain.
- remove_function(function)[source]
Removes a specific function from the chain.
- Parameters:
- functionCallable
The function to remove from the chain.
- replace_function(old_function, new_function)[source]
Replaces a specific function in the chain with a new one.
- Parameters:
- old_functionCallable
- new_functionCallable
The function to be replaced.
The function to replace the old one.
- validate_chain()[source]
Validates the function chain by ensuring all objects in the chain are callable and all functions except the last one return a dictionary.
- Raises:
- ValueError
If an object in the chain is not callable or a function does not return a dictionary.