MCPcopy Index your code
hub / github.com/Zipstack/unstract / run_command

Method run_command

runner/src/unstract/runner/runner.py:260–295  ·  view source on GitHub ↗

Runs any given command on the container. Args: command (str): Command to be executed. Returns: Optional[Any]: Response from container or None if error occures.

(self, command: str)

Source from the content-addressed store, hash-verified

258 return sidecar_config
259
260 def run_command(self, command: str) -> Any | None:
261 """Runs any given command on the container.
262
263 Args:
264 command (str): Command to be executed.
265
266 Returns:
267 Optional[Any]: Response from container or None if error occures.
268 """
269 command = command.upper()
270
271 # Get additional environment variables to pass to the container
272 additional_env = self._parse_additional_envs()
273
274 container_config = self.client.get_container_run_config(
275 command=["--command", command],
276 file_execution_id="",
277 auto_remove=True,
278 envs=additional_env,
279 )
280 container = None
281
282 # Run the Docker container
283 try:
284 container: ContainerInterface = self.client.run_container(container_config)
285 for text in container.logs(follow=True):
286 self.logger.info(f"[{container.name}] - {text}")
287 if f'"type": "{command}"' in text:
288 return json.loads(text)
289 except Exception as e:
290 self.logger.error(
291 f"Failed to run docker container: {e}", stack_info=True, exc_info=True
292 )
293 if container:
294 container.cleanup()
295 return None
296
297 def _get_container_command(
298 self, shared_log_dir: str, shared_log_file: str, settings: dict[str, Any]

Callers 1

run_commandFunction · 0.95

Calls 7

run_containerMethod · 0.45
logsMethod · 0.45
infoMethod · 0.45
errorMethod · 0.45
cleanupMethod · 0.45

Tested by

no test coverage detected