Implements: Container
Description
The AzureFunction class allows you to create an Abstract Azure Function that acts as a container to instantiate and run components and expose them via an external entry point.
Importan points
-
When handling calls, the “cmd” parameter determines the action that shall be called, while the other parameters are passed to the action itself.
-
The container configuration for this Azure Function is stored in "./config/config.yml" file. But this path can be overriden by CONFIG_PATH environment variable.
References
- *:logger:*:*:1.0: (optional) ILogger components to pass log messages
- *:counters:*:*:1.0: (optional) ICounters components to pass collected measurements
- *:service:azure-function:*:1.0: (optional) IAzureFunctionService services to handle action requests.
- *:service:commandable-azure-function:*:1.0: (optional) IAzureFunctionService services to handle action requests.
Constructors
Creates a new instance of this Azure Function.
AzureFunction(name: Optional[str], description: Optional[str])
- name: Optional[str] - (optional) container’s name (accessible via ContextInfo)
- description: Optional[str] - (optional) container’s description (accessible via ContextInfo)
Fields
Instance methods
act
Calls registered action in this Azure Function. “cmd” parameter in the action parameters determin what action shall be called.
This method shall only be used in testing.
act(self, context: HttpRequest): Any
- context: HttpRequest - action parameters.
- returns: Any - action result.
_execute
Executes this Azure Function and returns the result. This method can be overloaded in child classes if they need to change the default behavior
_execute(context: HttpRequest) -> Any
- context: HttpRequest - context the context parameters (or function arguments)
- returns: str - the result of the function execution.
_get_command
Returns command from Azure Function context. This method can be overloaded in child classes
_get_command(context: HttpRequest): str
- context: HttpRequest - Azure Function context
- returns: str - Returns command from context
_get_correlation_id
Returns correlationId from Azure Function context. This method can be overloaded in child classes
_get_correlation_id(context: HttpRequest): str
- context: HttpRequest - Azure Function context
- returns: str - Returns correlationId from context
get_handler
Return plugin function
get_handler(): Callable[[HttpRequest], Any]
- returns: Callable[[HttpRequest], Any] - plugin function
_instrument
Adds instrumentation to log calls and measures call time. It returns a Timing object that is used to end the time measurement.
_instrument(correlation_id: Optional[str], name: str): InstrumentTiming
- correlation_id: str - (optional) transaction id used to trace execution through the call chain.
- name: str - method’s name.
- returns: InstrumentTiming - Timing object to end the time measurement.
open
Opens the component.
open(correlation_id: Optional[str])
- correlation_id: Optional[str] - (optional) transaction id used to trace execution through the call chain.
_register_action
Registers an action in this Azure Function.
Note: This method has been deprecated. Use AzureFunctionService instead.
_register_action(cmd: str, schema: Schema, action: Callable[[HttpRequest], Any])
- cmd: str - a action/command name.
- schema: Schema - a validation schema to validate received parameters.
- action: Callable[[HttpRequest], Any] - an action function that is called when action is invoked.
register
Registers all actions in this Azure Function.
Note: Overloading of this method has been deprecated. Use AzureFunctionService instead.
register()
_register_services
Registers all Azure Function services in the container.
_register_services(context: any): string
run
Runs this Azure Function, loads container configuration, instantiate components and manage their lifecycle, makes this function ready to access action calls.
run()
set_references
Sets references to dependent components.
set_references(references: IReferences)
- references: IReferences - references to locate the component’s dependencies.
Examples
class MyAzureFunctionFunction(AzureFunction):
def __init__(self):
super().__init__("mygroup", "MyGroup Azure Function")
azure_function = MyAzureFunctionFunction()
service.run()
print("MyAzureFunctionFunction is started")