Component
elva.component
Module for generic asynchronous app component.
Classes:
-
Component
–Generic asynchronous app component class.
Component
Generic asynchronous app component class.
This class features graceful shutdown alongside annotated logging. It is used for writing providers, stores, parsers, renderers etc.
It supports explicit handling via the start
and stop
method as well as the asynchronous
context manager protocol.
Methods:
-
start
–Start the component.
-
stop
–Stop the component by cancelling all inner task groups.
-
before
–Hook to run before the component signals that is has been started.
-
run
–Hook to run after the component signals that is has been started.
-
cleanup
–Hook to run after the component's
stop
method
Attributes:
-
log
(Logger
) –Logger instance to write logging messages to.
-
started
(Event
) –Event signaling that the component has been started, i.e. is initialized and running.
-
stopped
(Event
) –Event signaling that the component has been stopped, i.e. deinitialized and not running.
log
instance-attribute
Logger instance to write logging messages to.
started
property
Event signaling that the component has been started, i.e. is initialized and running.
stopped
property
Event signaling that the component has been stopped, i.e. deinitialized and not running.
start(task_status=TASK_STATUS_IGNORED)
async
Start the component.
Parameters:
-
task_status
(TaskStatus[None]
, default:TASK_STATUS_IGNORED
) –The status to set when the task has started.
Source code in src/elva/component.py
stop()
async
Stop the component by cancelling all inner task groups.
before()
async
Hook to run before the component signals that is has been started.
In here, one would define initializing steps necessary for the component to run.
This method must return, otherwise the component will not set the
started
signal.
It is defined as a no-op and supposed to be implemented in the inheriting class.
Source code in src/elva/component.py
run()
async
Hook to run after the component signals that is has been started.
In here, one would define the main functionality of the component. This method may run indefinitely or return. The component is kept running regardless.
It is defined as a no-op and supposed to be implemented in the inheriting class.
Source code in src/elva/component.py
cleanup()
async
Hook to run after the component's stop
method
has been called and before it sets the stopped
event.
In here, one would define cleanup tasks such as closing connections.
This method must return, otherwise the component will not set the
stopped
signal.
It is defined as a no-op and supposed to be implemented in the inheriting class.