Execute a command immediately, optionally via the v2 request queue.
(**kwargs)
| 85 | @bp.route("/executecommand", methods=["POST"]) |
| 86 | @unified_api_decorator() |
| 87 | def execute_command_direct(**kwargs) -> Tuple[Union[Response, bytes], int]: |
| 88 | """Execute a command immediately, optionally via the v2 request queue.""" |
| 89 | temp_files = [] |
| 90 | queued_request_submitted = False |
| 91 | try: |
| 92 | processed_command, temp_files, request_error = _prepare_command_request() |
| 93 | if request_error: |
| 94 | return request_error |
| 95 | |
| 96 | if use_queue: |
| 97 | response_data, queued_request_submitted = _submit_queue_request( |
| 98 | processed_command, temp_files, wait_for_completion=True |
| 99 | ) |
| 100 | return response_data |
| 101 | |
| 102 | response, status_code = CommandExecutor.execute(processed_command) |
| 103 | |
| 104 | # If we get a busy response, add v1-specific message |
| 105 | if (isinstance(response, dict) and |
| 106 | "temporarily busy" in str(response.get("error", "")).lower()): |
| 107 | response["message"] = "Note: api/v1/executecommand only supports a single request at a time." |
| 108 | status_code = 503 |
| 109 | |
| 110 | return response if isinstance(response, bytes) else jsonify(response), status_code |
| 111 | |
| 112 | except Exception as e: |
| 113 | logger.error(f"Error executing command: {e}") |
| 114 | return jsonify({"status": "error", "error": f"Error: {str(e)}"}), 500 |
| 115 | finally: |
| 116 | # Queue-backed compatibility requests clean up files in the worker after submission. |
| 117 | if not use_queue or not queued_request_submitted: |
| 118 | RequestValidator.cleanup_temp_files(temp_files) |
| 119 | |
| 120 | return bp |
| 121 |
nothing calls this directly
no test coverage detected