Skip to main content

Crate isothrum_client

Crate isothrum_client 

Source
Expand description

The client of the Isothrum runner service.

One service per runner home (isothrum serve --home <home>) runs every operation of that home: one at a time per run, runs side by side, each operation’s events streamed to every subscriber. An app or the isothrum command line is its client: it sends commands, and follows the events.

Client::connect finds the home’s service through <home>/service.json and starts one when none answers. The wire protocol is in proto: newline-delimited JSON over a Unix domain socket in the home (owner-only) or a Windows named pipe (the user’s only).

§A service of another release

Client::connect takes the service it finds, whatever its release (it fails only when the service speaks another protocol). An app that bundles Isothrum wants its own release: Client::connect_exact connects only to a service of this crate’s VERSION and protocol, started from the build of the binary it would start (ServiceInfo::build: an app updated in place carries the same release, and its old service still runs the old program). It finds the one that runs, and when it is another release’s or another build’s:

  • it asks it to stop when idle (shutdown_if_idle, which every protocol keeps): one with operations queued or running is left running, and ClientError::Busy names them, for the app to tell its user (and connect again once they ended);
  • one that doesn’t answer is ended (its pid, from service.json) only when the home’s service lock is still held, the process with that pid started no later than the service said it did (a pid reused since is never ended), and the home’s journal shows no operation of it unfinished;
  • once it is gone (its lock released, its endpoint closed), binary is started, as Client::connect starts it, and the client connects, checking the new service is this release (ClientError::Version when binary is another).

The app reads none of the home’s files itself. Two apps replacing one home’s service take turns (<home>/service.replace.lock).

use isothrum_client::{Client, ClientError};

match Client::connect_exact(std::path::Path::new("/home/ada/.isothrum"), Some(bundled)).await {
    Ok(client) => assert_eq!(client.service().version, isothrum_client::VERSION),
    Err(ClientError::Busy { version, operations, .. }) => {
        println!("Isothrum {version} is still running {} operation(s): try again once they end", operations.len());
    }
    Err(e) => return Err(e),
}
use isothrum_client::{Client, proto::{Command, OpOptions, Target}};

let client = Client::connect(std::path::Path::new("/home/ada/.isothrum"), None).await?;
let up = Command::Up {
    target: Target::new("/stacks/web", None),
    options: OpOptions::default(),
    lifetime_s: None,
};
let mut operation = client.follow(up).await?;
while let Some(event) = operation.next().await {
    println!("{:?}", event?);
}

Modules§

proto
The service’s wire protocol, version PROTOCOL: newline-delimited JSON (one object per line, UTF-8, at most MAX_LINE bytes) over the home’s local endpoint.
v1
The shared types of the 3.0 state model the protocol carries, as the runner defines them (OperationId, EventCursor, events v1, the journal’s rows), and what a client reads of an event.
wire
One connection to a service: JSON lines over the local endpoint, both ways.

Structs§

Accepted
An operation the service queued.
Client
A connection to a home’s runner service.
Followed
An operation queued and followed (Client::follow).
HeldConsole
A graphical console (Client::graphical_console): where it answers and how to sign in, and the connection that keeps its tunnel open. Dropping it closes the connection, and the service ends the tunnel.
InputVariable
One input variable of a Terraform module, as its variable block declares it.
Pool
The connections of a process to its homes’ services, one per home (Pool::new: real Clients; a test hands its own connection type to Pool::with).
ServiceInfo
What a running service writes to <home>/service.json once it listens.
ServicePaths
The files of a home’s service.
Subscription
A subscription: the events of the stream, each with its cursor. It ends when the service closes the connection (an error item says so); dropping it unsubscribes.

Enums§

ClientError
Why a client call failed.

Constants§

BUILD_ENV
The variable a client gives the service it starts: the build of the binary it started (build_of), which the service writes as its ServiceInfo::build.
VERSION
This crate’s release: the version Client::connect_exact wants of a service.

Functions§

build_of
The build of the executable at path: its size and modification time (<bytes>-<nanoseconds since the epoch>), which an update of the program changes; none when it can’t be read. Two versions of an app may carry the same release of Isothrum: this tells them apart.