Dispatch command to appropriate handler. Args: message: Request message dict Returns: Response dictionary
(self, message: dict)
| 263 | pass |
| 264 | |
| 265 | async def _dispatch(self, message: dict) -> dict: |
| 266 | """ |
| 267 | Dispatch command to appropriate handler. |
| 268 | |
| 269 | Args: |
| 270 | message: Request message dict |
| 271 | |
| 272 | Returns: |
| 273 | Response dictionary |
| 274 | """ |
| 275 | request_id = message.get("id", 0) |
| 276 | command = message.get("command", "").strip() |
| 277 | args = message.get("args", []) |
| 278 | |
| 279 | if not command: |
| 280 | return make_error_response(request_id, "Empty command") |
| 281 | |
| 282 | try: |
| 283 | # Parse command (e.g., "show workers" or "worker add 2") |
| 284 | parts = shlex.split(command) |
| 285 | if args: |
| 286 | parts.extend(str(a) for a in args) |
| 287 | |
| 288 | if not parts: |
| 289 | return make_error_response(request_id, "Empty command") |
| 290 | |
| 291 | # Route to handler |
| 292 | result = self._execute_command(parts) |
| 293 | return make_response(request_id, result) |
| 294 | |
| 295 | except ValueError as e: |
| 296 | return make_error_response(request_id, f"Invalid argument: {e}") |
| 297 | except Exception as e: |
| 298 | if self.arbiter.log: |
| 299 | self.arbiter.log.exception("Command error") |
| 300 | return make_error_response(request_id, f"Command failed: {e}") |
| 301 | |
| 302 | def _execute_command(self, parts: list) -> dict: # pylint: disable=too-many-return-statements |
| 303 | """ |
no test coverage detected