Handle BUSY instance by enqueuing or returning error.
(
self,
request_id: str,
instance: UnityInstance,
command: str,
params: dict[str, Any],
timeout_ms: int,
)
| 608 | return False |
| 609 | |
| 610 | async def _enqueue_command( |
| 611 | self, |
| 612 | request_id: str, |
| 613 | instance: UnityInstance, |
| 614 | command: str, |
| 615 | params: dict[str, Any], |
| 616 | timeout_ms: int, |
| 617 | ) -> dict[str, Any]: |
| 618 | """Handle BUSY instance by enqueuing or returning error.""" |
| 619 | if not instance.queue_enabled: |
| 620 | detail_suffix = f" ({instance.status_detail})" if instance.status_detail else "" |
| 621 | return ErrorMessage.from_code( |
| 622 | request_id, |
| 623 | ErrorCode.INSTANCE_BUSY, |
| 624 | f"Instance is busy{detail_suffix}: {instance.instance_id}. Retry the command after a few seconds.", |
| 625 | ).to_dict() |
| 626 | |
| 627 | future: asyncio.Future[dict[str, Any]] = asyncio.Future() |
| 628 | queued_cmd = QueuedCommand( |
| 629 | request_id=request_id, |
| 630 | command=command, |
| 631 | params=params, |
| 632 | timeout_ms=timeout_ms, |
| 633 | future=future, |
| 634 | ) |
| 635 | |
| 636 | if not instance.enqueue_command(queued_cmd): |
| 637 | return ErrorMessage.from_code( |
| 638 | request_id, |
| 639 | ErrorCode.QUEUE_FULL, |
| 640 | f"Command queue is full (max: {QUEUE_MAX_SIZE}): {instance.instance_id}. Wait for current commands to complete before sending new ones.", |
| 641 | ).to_dict() |
| 642 | |
| 643 | logger.info(f"[{request_id}] Command queued for {instance.instance_id} (queue size: {instance.queue_size})") |
| 644 | try: |
| 645 | return await asyncio.wait_for(future, timeout=timeout_ms / 1000) |
| 646 | except TimeoutError: |
| 647 | return ErrorMessage.from_code( |
| 648 | request_id, |
| 649 | ErrorCode.TIMEOUT, |
| 650 | f"Queued command timed out after {timeout_ms}ms. The command was queued but did not complete in time. Consider increasing --timeout or retrying.", |
| 651 | ).to_dict() |
| 652 | |
| 653 | async def _execute_command( |
| 654 | self, |
no test coverage detected