Wait for a Unity instance to become ready.
(
self,
request_id: str,
instance_id: str | None,
)
| 525 | return instance.status in (InstanceStatus.RELOADING, InstanceStatus.DISCONNECTED) or not instance.is_connected |
| 526 | |
| 527 | async def _wait_for_instance( |
| 528 | self, |
| 529 | request_id: str, |
| 530 | instance_id: str | None, |
| 531 | ) -> UnityInstance | dict[str, Any]: |
| 532 | """Wait for a Unity instance to become ready.""" |
| 533 | max_wait_ms = 15000 |
| 534 | poll_interval_ms = 250 |
| 535 | waited_ms = 0 |
| 536 | |
| 537 | while waited_ms < max_wait_ms: |
| 538 | result = self._get_instance_or_error(request_id, instance_id) |
| 539 | if isinstance(result, dict): |
| 540 | return result |
| 541 | |
| 542 | if result is None: |
| 543 | if not self._should_wait_for_missing(request_id, instance_id, waited_ms): |
| 544 | return ErrorMessage.from_code( |
| 545 | request_id, |
| 546 | ErrorCode.INSTANCE_NOT_FOUND, |
| 547 | f"Instance not found: {instance_id}. Check available instances with 'u instances'.", |
| 548 | ).to_dict() |
| 549 | elif not self._instance_needs_wait(result): |
| 550 | break |
| 551 | elif waited_ms == 0: |
| 552 | logger.info(f"[{request_id}] Instance not ready ({result.status}), waiting...") |
| 553 | |
| 554 | await asyncio.sleep(poll_interval_ms / 1000) |
| 555 | waited_ms += poll_interval_ms |
| 556 | |
| 557 | return self._validate_waited_instance(request_id, instance_id, waited_ms) |
| 558 | |
| 559 | def _validate_waited_instance( |
| 560 | self, |
no test coverage detected