pub struct CommandClient { /* private fields */ }Expand description
High-level client that talks to Cloudflare’s host-managed command channel (Cloud Run does not expose one).
Commands are framed as JSON lines and travel over stdin/stdout (default), TCP, or
Unix sockets (when enabled). Responses are deserialized back into CommandResponse
instances and surfaced through async APIs.
§Transport Modes
stdio: bidirectional pipes that the Workers container sidecar keeps open.tcp://host:port: an explicit TCP socket managed by the sidecar.unix://path(Unix only): a Unix domain socket exposed by the sidecar.
§Errors
All async constructors and CommandClient::send return CommandError when the transport
cannot be established, the host drops the channel, or the host reports a failure.
§Examples
use containerflare_command::{CommandClient, CommandEndpoint, CommandRequest};
let client = CommandClient::connect(CommandEndpoint::Stdio).await?;
let response = client.send(CommandRequest::empty("health_check")).await?;
assert!(response.ok);Implementations§
Source§impl CommandClient
impl CommandClient
Sourcepub async fn connect(endpoint: CommandEndpoint) -> Result<Self, CommandError>
pub async fn connect(endpoint: CommandEndpoint) -> Result<Self, CommandError>
Connects to the configured endpoint using the default timeout.
§Parameters
endpoint- Transport descriptor (stdio, TCP, or Unix socket).
§Returns
A connected CommandClient ready to issue commands.
§Errors
Returns CommandError if the underlying transport cannot be opened or is closed
before the connection is established.
§Panics
Does not panic.
Sourcepub async fn connect_with_timeout(
endpoint: CommandEndpoint,
timeout: Duration,
) -> Result<Self, CommandError>
pub async fn connect_with_timeout( endpoint: CommandEndpoint, timeout: Duration, ) -> Result<Self, CommandError>
Connects to the endpoint and enforces a custom read timeout.
§Parameters
endpoint- Transport descriptor (stdio, TCP, or Unix socket).timeout- Maximum duration to wait for each response before failing.
§Returns
A connected CommandClient that enforces the provided timeout for every command.
§Errors
Returns CommandError if the underlying transport cannot be opened or the timeout
elapses while establishing the connection.
§Panics
Does not panic.
Creates a CommandClient that always reports an unavailable channel.
This is useful for runtimes (Google Cloud Run, local testing, etc.) that do not expose a host-managed command bus but still want to share the API surface.
Sourcepub fn endpoint(&self) -> &CommandEndpoint
pub fn endpoint(&self) -> &CommandEndpoint
Returns the endpoint backing this client.
Sourcepub async fn send(
&self,
request: CommandRequest,
) -> Result<CommandResponse, CommandError>
pub async fn send( &self, request: CommandRequest, ) -> Result<CommandResponse, CommandError>
Sends a command request and waits for a response (or timeout).
§Parameters
request- Structured command for the Workers sidecar.
§Returns
The CommandResponse emitted by the sidecar.
§Errors
Returns CommandError if the channel closes, the response payload cannot be
deserialized, the command reports a failure, or the read timeout elapses.
§Panics
Does not panic.
Trait Implementations§
Source§impl Clone for CommandClient
impl Clone for CommandClient
Source§fn clone(&self) -> CommandClient
fn clone(&self) -> CommandClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more