fastiot.core.service_annotations module¶
Decorator functions to add the basic functionality to FastIoT Services
- fastiot.core.service_annotations.subscribe(subject)[source]¶
Decorator method for methods subscribing to a subject. The decorated method must have either one or two arguments:
subscribe_something(message: Type[FastIoTData])
subscribe_something(subject_name: str, message: Type[FastIoTData])
See Publish, subscribe, request and reply in your service for more details.
- Parameters:
subject (
Subject
) – The subject (fastiot.core.data_models.Subject
) to subscribe.
- fastiot.core.service_annotations.reply(subject)[source]¶
Decorator for methods replying on the specified subject. This works similiar to
fastiot.core.service_annotations.subscribe()
but you have to return aMsg
as a reply message.- Parameters:
subject (
ReplySubject
) – The subject to subscribe to for sending replies
- fastiot.core.service_annotations.loop(fn)[source]¶
Decorator function for methods to run continuously. This will basically create a “while True loop” wrapper around the provided function. This is purely syntactic suggar for run_task.
Your method needs to return an awaitable that is awaited after each loop execution before the next iteration. However, the returned awaitable does not finish if a service shutdown is requested. It uses
self.run_coro
under the hood. But it is guaranteed, that the annotated loop function is awaited and not interrupted if a shutdown is requested.- Example:
@loop async def log_still_running(self):
logging.info(“Service is still running.”) return asyncio.sleep(10.0)