diff --git a/CHANGELOG.md b/CHANGELOG.md index 9340582..0340b02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 0.6.3 - July 26, 2023 + +### 🚨 Removed + +* Deleted legacy lab code to write log data and Google Sheets + +### ✨ Improved + +* The actor now emits its status on a timer with delay configurable as `status_delay`. With this `cerebro` is not required to ask for the status directly. + + ## 0.6.2 - July 26, 2023 ### ✨ Improved diff --git a/python/lvmscp/actor/actor.py b/python/lvmscp/actor/actor.py index 97634f5..df20e2c 100644 --- a/python/lvmscp/actor/actor.py +++ b/python/lvmscp/actor/actor.py @@ -47,18 +47,41 @@ def __init__(self, *args, **kwargs): assert self.model - self.read_credentials() - - # Add Google API client - try: - self.google_client = self.get_google_client() - except Exception as err: - warnings.warn(f"Failed authenticating with Google: {err}", ArchonWarning) - self.google_client = None - - # Model callbacks - self._log_lock = asyncio.Lock() - self.model["filenames"].register_callback(self.fill_log) + self.emit_status_task: asyncio.Task | None = None + + async def start(self): + """Starts the actor.""" + + start_result = await super().start() + + delay = self.config.get("status_delay", 30.0) + self.emit_status_task = asyncio.create_task(self.emit_status(delay)) + + return start_result + + async def stop(self): + """Stops the actor and cancels tasks.""" + + if self.emit_status_task and not self.emit_status_task.done(): + self.emit_status_task.cancel() + with suppress(asyncio.CancelledError): + await self.emit_status_task + + return await super().stop() + + async def emit_status(self, delay: float = 30.0): + """Emits the status of the controller on a timer.""" + + await asyncio.sleep(5) + + while True: + await Command( + "status", + actor=self, + commander_id=f".{self.name}", + ).parse() + + await asyncio.sleep(delay) def merge_schemas(self, scp_schema_path: str | None = None): """Merge default schema with SCP one.""" diff --git a/python/lvmscp/etc/lvmscp.yml b/python/lvmscp/etc/lvmscp.yml index 7af3b81..105a9aa 100644 --- a/python/lvmscp/etc/lvmscp.yml +++ b/python/lvmscp/etc/lvmscp.yml @@ -157,6 +157,8 @@ checksum: write: true mode: md5 +status_delay: 30.0 + # Actor configuration for the AMQPActor class actor: name: lvmscp