Skip to content

Commit

Permalink
Emit status on a timer
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Jul 26, 2023
1 parent 360f291 commit 5cf91e5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
47 changes: 35 additions & 12 deletions python/lvmscp/actor/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 2 additions & 0 deletions python/lvmscp/etc/lvmscp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ checksum:
write: true
mode: md5

status_delay: 30.0

# Actor configuration for the AMQPActor class
actor:
name: lvmscp
Expand Down

0 comments on commit 5cf91e5

Please sign in to comment.