Skip to main content

Module connector

Module connector 

Source
Expand description

Connector trait for shell command execution.

This module provides the Connector trait, a simple abstraction for running shell commands either locally or on remote compute resources. Unlike the Sandbox trait which provides a higher-level interface for test execution, connectors are a lower-level primitive focused purely on command execution.

§Architecture

┌─────────────────────────────────────────────────┐
│                   Caller                        │
│         (decides what commands to run)          │
└─────────────────────┬───────────────────────────┘
                      │
                      ▼
┌─────────────────────────────────────────────────┐
│              Connector Trait                    │
│   run() - buffered execution                    │
│   run_stream() - streaming output               │
└─────────────────────┬───────────────────────────┘
                      │
          ┌───────────┴───────────┐
          ▼                       ▼
┌─────────────────┐     ┌─────────────────┐
│ ShellConnector  │     │ Custom Connector│
│ (local shell)   │     │ (API, etc)      │
└─────────────────┘     └─────────────────┘

§Built-in Connectors

ConnectorDescription
ShellConnectorExecutes commands via local shell (sh -c)

§Example: Using ShellConnector

use offload::connector::{Connector, ShellConnector};

let connector = ShellConnector::new()
    .with_working_dir("/path/to/project".into())
    .with_timeout(300);

let result = connector.run("pytest tests/ --collect-only -q").await?;

if result.exit_code == 0 {
    println!("Tests discovered:\n{}", result.stdout);
}

§Example: Streaming Output

use offload::connector::{Connector, ShellConnector};
use offload::provider::OutputLine;
use futures::StreamExt;

let connector = ShellConnector::new();
let mut stream = connector.run_stream("pytest tests/ -v").await?;

while let Some(line) = stream.next().await {
    match line {
        OutputLine::Stdout(s) => println!("{}", s),
        OutputLine::Stderr(s) => eprintln!("{}", s),
        OutputLine::ExitCode(code) => println!("Exit: {}", code),
    }
}

Structs§

ExecResult
Result from a shell command execution.
ShellConnector
A connector that executes commands via the local shell.

Traits§

Connector
Trait for connectors that execute shell commands.