1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! 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`).
//!
//! ```no_run
//! # async fn demo(bundled: &std::path::Path) -> Result<(), isothrum_client::ClientError> {
//! 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),
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ```no_run
//! # async fn demo() -> Result<(), isothrum_client::ClientError> {
//! 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?);
//! }
//! # Ok(())
//! # }
//! ```
pub use ;
pub use ;
pub use ClientError;
pub use InputVariable;
pub use Pool;
/// This crate's release: the version [`Client::connect_exact`] wants of a service.
pub const VERSION: &str = env!;