Delegate Manager¶
Overview¶
RPA is driven by a powerful delegate manager, which makes it easy to observe and respond to any method invoked by the user. Rather than relying on PySide signals for each method, users can simply attach a pre or post delegate to react to user interactions. This streamlines the workflow and provides a flexible, centralized way to handle behavior across the system.
Why Delegate Manager?¶
Having a Delegate Manager per RPA module enables RPA users to,
Add the core delegate to each RPA methods
Set permissions on each of the RPA methods
Listen to any RPA method calls and decorate them with callables that will be called before or after the core delegate is called.
What is a Delegate?¶
A delegate is any Python callable that needs to be called when an RPA method is called.
What is the delegate-manager?¶
Every RPA module has a delegate manager. When a particular method of an RPA module is called, it will use it’s module’s delegate manager to call all the delegates that are associated with the method.
Types of Delegates:¶
Following are the 4 types of delegates that any RPA method can have. And the delegates will be called in the following order as well.
Permission Delegates
Pre Delegates
Core Delegate
Post Delegates
Permission Delegates:¶
An RPA method can have 0 or more permission delegates. In order for the Pre Delegates, Core Delegate and Post Delegates of a given method to be called, all the Permission Delegates of a given method needs to return True. Note that the given delegate(callable) will be receiving the same args and kwargs that are passed to the rpa_method.
Note that the given delegate(callable) will be receiving the same args and kwargs that are passed to the rpa_method as its inputs. Hence signature of the callable should look like this,
def permission_delegate(self, *args, **kwargs):
pass
Instead of *args and **kwargs you can have the actual args and kwargs based on the rpa_method.
Pre Delegates:¶
An RPA method can have 0 or more pre delegates. These are the delegates that get called before the core delegate is called. Note that the given delegate(callable) will be receiving the same args and kwargs that are passed to the rpa_method.
Note that the given delegate(callable) will be receiving the same args and kwargs that are passed to the rpa_method as its inputs. Hence signature of the callable should look like this,
def pre_delegate(self, *args, **kwargs):
pass
Instead of *args and **kwargs you can have the actual args and kwargs based on the rpa_method.
Core Delegate:¶
An RPA method can have 0 or 1 core delegate. This is the actual delegate that needs to be called when the user calls the RPA method. The output of this delegate is what is returned back to the called of the RPA method. If no delegate is present for a RPA method then None will be returned.
Post Delegates:¶
An RPA method can have 0 or more post delegates. These are the delegates that get called after the core delegate is called.
Note that the given delegate(callable) will be receiving the output of the main delegate as it’s first argument and the same args and kwargs that are passed to the rpa_method as the subsequent inputs. Hence signature of the callable should look like this,
def post_delegate(self, out, *args, **kwargs):
pass
Instead of *args and **kwargs you can have the actual args and kwargs based on the rpa_method.
- class rpa.delegate_mngr.DelegateMngr(logger)[source]
Bases:
object
- add_permission_delegate(rpa_method: Callable, delegate: Callable) None [source]
An RPA method can have 0 or more permission delegates. In order for the Pre Delegates, Core Delegate and Post Delegates of a given method to be called, all the Permission Delegates of a given method needs to return True. Note that the given delegate(callable) will be receiving the same args and kwargs that are passed to the rpa_method.
Note that the given delegate(callable) will be receiving the same args and kwargs that are passed to the rpa_method as its inputs. Hence signature of the callable should look like this,
def permission_delegate(self, *args, **kwargs): pass
Instead of *args and **kwargs you can have the actual args and kwargs based on the rpa_method.
- Parameters:
rpa_method (callable) – A method of an RPA module
delegate (callable) – Callable that returns a boolean value of True or False.
- Returns:
None
- add_post_delegate(rpa_method: Callable, delegate: Callable) None [source]
An RPA method can have 0 or more post delegates. These are the delegates that get called after the core delegate is called.
Note that the given delegate(callable) will be receiving the output of the main delegate as it’s first argument and the same args and kwargs that are passed to the rpa_method as the subsequent inputs. Hence signature of the callable should look like this,
def post_delegate(self, out, *args, **kwargs): pass
Instead of *args and **kwargs you can have the actual args and kwargs based on the rpa_method.
- Parameters:
rpa_method (callable) – A method of an RPA module
delegate (callable) – Callable that needs to be called after core delegate
- Returns:
None
- add_pre_delegate(rpa_method: Callable, delegate: Callable) None [source]
An RPA method can have 0 or more pre delegates. These are the delegates that get called before the core delegate is called. Note that the given delegate(callable) will be receiving the same args and kwargs that are passed to the rpa_method.
Note that the given delegate(callable) will be receiving the same args and kwargs that are passed to the rpa_method as its inputs. Hence signature of the callable should look like this,
def pre_delegate(self, *args, **kwargs): pass
Instead of *args and **kwargs you can have the actual args and kwargs based on the rpa_method.
- Parameters:
rpa_method (callable) – A method of an RPA module
delegate (callable) – Callable that needs to be called before core delegate
- Returns:
None
- call(rpa_method: Callable, args: List | None = None, kwargs: Dict | None = None) Any [source]
Call all the delegates associated with the given rpa_method with the provided args and kwargs.
- Parameters:
rpa_method (callable) – A method of an RPA module
args (List[Any]) – List of arguments to the passed to the delegates
kwargs (Dict) – Dict of key-word arguments to the passed to the delegates
- Returns:
Value returned by core delegate callable
- Return type:
(Any)
- clear_permission_delegates(rpa_method: Callable) None [source]
Clears all permission delegates for the given rpa method.
- Parameters:
rpa_method (callable) – A method of an RPA module
- Returns:
None
- clear_post_delegates(rpa_method: Callable) None [source]
Clears all post delegates for the given rpa method.
- Parameters:
rpa_method (callable) – A method of an RPA module
- Returns:
None
- clear_pre_delegates(rpa_method: Callable) None [source]
Clears all pre delegates for the given rpa method.
- Parameters:
rpa_method (callable) – A method of an RPA module
- Returns:
None
- get_permission_delegates(rpa_method: Callable) List[Callable] [source]
Get list of all permission-delegates of the given rpa method.
- Parameters:
rpa_method (callable) – A method of an RPA module
- Returns:
None
- get_post_delegates(rpa_method: Callable) List[Callable] [source]
Get list of all post-delegates of the given rpa method.
- Parameters:
rpa_method (callable) – A method of an RPA module
- Returns:
None
- get_pre_delegates(rpa_method: Callable) List[Callable] [source]
Get list of all pre-delegates of the given rpa method.
- Parameters:
rpa_method (callable) – A method of an RPA module
- Returns:
None
- remove_permission_delegate(rpa_method: Callable, delegate: Callable) None [source]
Remove the given deletegate as a permission delegate for the given rpa method.
- Parameters:
rpa_method (callable) – A method of an RPA module
delegate (callable) – Callable that was previously set as a permission delegate of the given rpa_method.
- Returns:
None
- remove_post_delegate(rpa_method: Callable, delegate: Callable) None [source]
Remove the given deletegate as a post delegate for the given rpa method.
- Parameters:
rpa_method (callable) – A method of an RPA module
delegate (callable) – Callable that was previously set as a post delegate of the given rpa_method.
- Returns:
None
- remove_pre_delegate(rpa_method: Callable, delegate: Callable) None [source]
Remove the given deletegate as a pre delegate for the given rpa method.
- Parameters:
rpa_method (callable) – A method of an RPA module
delegate (callable) – Callable that was previously set as a pre delegate of the given rpa_method.
- Returns:
None