fastiot.core.service module¶
- class fastiot.core.service.FastIoTService(broker_connection, **kwargs)[source]¶
This is the most base class for all FastIoT Services. Your service must inherit from this class for everything to work.
- classmethod main(**kwargs)[source]¶
Entrypoint of the class; this is the method to be started using e.g. a
run.py
like generated when creating a new service. Do not overwrite, unless you know exactly what you are doing.- Parameters:
kwargs – kwargs will be passed to class constructor.
- run_task(coro)[source]¶
Creates an asyncio-Task which is managed by this class. If the execution of the coroutine raises an exception, they are logged and a service shutdown is requested. If the task terminates reguarly, it is dropped and the module continuous to run.
The task is awaited after _stop() has been called.
- async wait_for_shutdown(timeout=0.0)[source]¶
Method to wait for service shutdown. This is helpfull if you have a loop running forever till the service needs to shutdown.
Shutdown may occur when some other parts of the service fail like database connection or broker connection.
Per default, it will wait indefinetly, but you can specify a timeout. If timeout exceeds, it will not raise a timeout error, but instead return false. Otherwise it will return true.
Example: >>> while await self.wait_for_shutdown(1.0) is False: >>> print(“Still running…”)
- Return type:
bool
- Parameters:
timeout (
float
) – Specify a time you want to wait for the shutdown. A value of 0.0 (default) will wait indefinetly.
:result Return true if shutdown is requested, false if timeout occured.