Skip to main content

ControlClient

Struct ControlClient 

Source
pub struct ControlClient { /* private fields */ }

Implementations§

Source§

impl ControlClient

Source

pub fn builder(socket: impl Into<String>) -> ControlClientBuilder

Examples found in repository?
examples/control.rs (line 14)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let mut args = env::args().skip(1);
7    let action = args.next().unwrap_or_else(|| "status".to_string());
8
9    let socket =
10        env::var("FALCORN_CONTROL_SOCKET").unwrap_or_else(|_| DEFAULT_CONTROL_SOCKET.to_string());
11    let token = env::var("FALCORN_CONTROL_TOKEN").ok();
12    let client_name = env::var("FALCORN_CONTROL_CLIENT").ok();
13
14    let mut builder = ControlClient::builder(socket);
15    if let Some(token) = token {
16        builder = builder.auth_token(token);
17    }
18    if let Some(client_name) = client_name {
19        builder = builder.client_name(client_name);
20    }
21
22    let mut client = builder.connect()?;
23
24    match action.as_str() {
25        "status" => {
26            let status = client.get_status()?;
27            println!("{:#?}", status);
28        }
29        "workers" => {
30            let workers = client.get_workers()?;
31            println!("{:#?}", workers);
32        }
33        "show-config" => {
34            let config = client.show_config()?;
35            println!("{}", config);
36        }
37        "scale" => {
38            let workers = args
39                .next()
40                .ok_or("scale requires worker count")?
41                .parse::<usize>()?;
42            let message = client.scale_to(workers)?;
43            println!("{}", message);
44        }
45        "restart" => {
46            let id = args.next().and_then(|value| value.parse::<u32>().ok());
47            let force = args.any(|value| value == "--force");
48            let message = client.restart_worker(id, !force)?;
49            println!("{}", message);
50        }
51        "shutdown" => {
52            let force = args.any(|value| value == "--force");
53            let message = client.shutdown(!force)?;
54            println!("{}", message);
55        }
56        "reload" => {
57            let mut path = None;
58            let mut rolling = true;
59            for value in args {
60                if value == "--no-rolling" {
61                    rolling = false;
62                } else if value.starts_with("--path=") {
63                    path = value.split('=').nth(1).map(|s| s.to_string());
64                } else if path.is_none() {
65                    path = Some(value);
66                }
67            }
68            let message = client.reload_config(path, rolling)?;
69            println!("{}", message);
70        }
71        other => {
72            eprintln!(
73                "Unknown action: {} (use status|workers|show-config|scale|restart|shutdown|reload)",
74                other
75            );
76        }
77    }
78
79    Ok(())
80}
Source

pub fn send_action( &mut self, action: ActionKind, payload: Option<ActionRequestPayload>, ) -> Result<ActionResponse>

Source

pub fn get_status(&mut self) -> Result<StatusSnapshot>

Examples found in repository?
examples/control.rs (line 26)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let mut args = env::args().skip(1);
7    let action = args.next().unwrap_or_else(|| "status".to_string());
8
9    let socket =
10        env::var("FALCORN_CONTROL_SOCKET").unwrap_or_else(|_| DEFAULT_CONTROL_SOCKET.to_string());
11    let token = env::var("FALCORN_CONTROL_TOKEN").ok();
12    let client_name = env::var("FALCORN_CONTROL_CLIENT").ok();
13
14    let mut builder = ControlClient::builder(socket);
15    if let Some(token) = token {
16        builder = builder.auth_token(token);
17    }
18    if let Some(client_name) = client_name {
19        builder = builder.client_name(client_name);
20    }
21
22    let mut client = builder.connect()?;
23
24    match action.as_str() {
25        "status" => {
26            let status = client.get_status()?;
27            println!("{:#?}", status);
28        }
29        "workers" => {
30            let workers = client.get_workers()?;
31            println!("{:#?}", workers);
32        }
33        "show-config" => {
34            let config = client.show_config()?;
35            println!("{}", config);
36        }
37        "scale" => {
38            let workers = args
39                .next()
40                .ok_or("scale requires worker count")?
41                .parse::<usize>()?;
42            let message = client.scale_to(workers)?;
43            println!("{}", message);
44        }
45        "restart" => {
46            let id = args.next().and_then(|value| value.parse::<u32>().ok());
47            let force = args.any(|value| value == "--force");
48            let message = client.restart_worker(id, !force)?;
49            println!("{}", message);
50        }
51        "shutdown" => {
52            let force = args.any(|value| value == "--force");
53            let message = client.shutdown(!force)?;
54            println!("{}", message);
55        }
56        "reload" => {
57            let mut path = None;
58            let mut rolling = true;
59            for value in args {
60                if value == "--no-rolling" {
61                    rolling = false;
62                } else if value.starts_with("--path=") {
63                    path = value.split('=').nth(1).map(|s| s.to_string());
64                } else if path.is_none() {
65                    path = Some(value);
66                }
67            }
68            let message = client.reload_config(path, rolling)?;
69            println!("{}", message);
70        }
71        other => {
72            eprintln!(
73                "Unknown action: {} (use status|workers|show-config|scale|restart|shutdown|reload)",
74                other
75            );
76        }
77    }
78
79    Ok(())
80}
Source

pub fn get_workers(&mut self) -> Result<Vec<WorkerSnapshot>>

Examples found in repository?
examples/control.rs (line 30)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let mut args = env::args().skip(1);
7    let action = args.next().unwrap_or_else(|| "status".to_string());
8
9    let socket =
10        env::var("FALCORN_CONTROL_SOCKET").unwrap_or_else(|_| DEFAULT_CONTROL_SOCKET.to_string());
11    let token = env::var("FALCORN_CONTROL_TOKEN").ok();
12    let client_name = env::var("FALCORN_CONTROL_CLIENT").ok();
13
14    let mut builder = ControlClient::builder(socket);
15    if let Some(token) = token {
16        builder = builder.auth_token(token);
17    }
18    if let Some(client_name) = client_name {
19        builder = builder.client_name(client_name);
20    }
21
22    let mut client = builder.connect()?;
23
24    match action.as_str() {
25        "status" => {
26            let status = client.get_status()?;
27            println!("{:#?}", status);
28        }
29        "workers" => {
30            let workers = client.get_workers()?;
31            println!("{:#?}", workers);
32        }
33        "show-config" => {
34            let config = client.show_config()?;
35            println!("{}", config);
36        }
37        "scale" => {
38            let workers = args
39                .next()
40                .ok_or("scale requires worker count")?
41                .parse::<usize>()?;
42            let message = client.scale_to(workers)?;
43            println!("{}", message);
44        }
45        "restart" => {
46            let id = args.next().and_then(|value| value.parse::<u32>().ok());
47            let force = args.any(|value| value == "--force");
48            let message = client.restart_worker(id, !force)?;
49            println!("{}", message);
50        }
51        "shutdown" => {
52            let force = args.any(|value| value == "--force");
53            let message = client.shutdown(!force)?;
54            println!("{}", message);
55        }
56        "reload" => {
57            let mut path = None;
58            let mut rolling = true;
59            for value in args {
60                if value == "--no-rolling" {
61                    rolling = false;
62                } else if value.starts_with("--path=") {
63                    path = value.split('=').nth(1).map(|s| s.to_string());
64                } else if path.is_none() {
65                    path = Some(value);
66                }
67            }
68            let message = client.reload_config(path, rolling)?;
69            println!("{}", message);
70        }
71        other => {
72            eprintln!(
73                "Unknown action: {} (use status|workers|show-config|scale|restart|shutdown|reload)",
74                other
75            );
76        }
77    }
78
79    Ok(())
80}
Source

pub fn show_config(&mut self) -> Result<String>

Examples found in repository?
examples/control.rs (line 34)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let mut args = env::args().skip(1);
7    let action = args.next().unwrap_or_else(|| "status".to_string());
8
9    let socket =
10        env::var("FALCORN_CONTROL_SOCKET").unwrap_or_else(|_| DEFAULT_CONTROL_SOCKET.to_string());
11    let token = env::var("FALCORN_CONTROL_TOKEN").ok();
12    let client_name = env::var("FALCORN_CONTROL_CLIENT").ok();
13
14    let mut builder = ControlClient::builder(socket);
15    if let Some(token) = token {
16        builder = builder.auth_token(token);
17    }
18    if let Some(client_name) = client_name {
19        builder = builder.client_name(client_name);
20    }
21
22    let mut client = builder.connect()?;
23
24    match action.as_str() {
25        "status" => {
26            let status = client.get_status()?;
27            println!("{:#?}", status);
28        }
29        "workers" => {
30            let workers = client.get_workers()?;
31            println!("{:#?}", workers);
32        }
33        "show-config" => {
34            let config = client.show_config()?;
35            println!("{}", config);
36        }
37        "scale" => {
38            let workers = args
39                .next()
40                .ok_or("scale requires worker count")?
41                .parse::<usize>()?;
42            let message = client.scale_to(workers)?;
43            println!("{}", message);
44        }
45        "restart" => {
46            let id = args.next().and_then(|value| value.parse::<u32>().ok());
47            let force = args.any(|value| value == "--force");
48            let message = client.restart_worker(id, !force)?;
49            println!("{}", message);
50        }
51        "shutdown" => {
52            let force = args.any(|value| value == "--force");
53            let message = client.shutdown(!force)?;
54            println!("{}", message);
55        }
56        "reload" => {
57            let mut path = None;
58            let mut rolling = true;
59            for value in args {
60                if value == "--no-rolling" {
61                    rolling = false;
62                } else if value.starts_with("--path=") {
63                    path = value.split('=').nth(1).map(|s| s.to_string());
64                } else if path.is_none() {
65                    path = Some(value);
66                }
67            }
68            let message = client.reload_config(path, rolling)?;
69            println!("{}", message);
70        }
71        other => {
72            eprintln!(
73                "Unknown action: {} (use status|workers|show-config|scale|restart|shutdown|reload)",
74                other
75            );
76        }
77    }
78
79    Ok(())
80}
Source

pub fn scale_to(&mut self, workers: usize) -> Result<String>

Examples found in repository?
examples/control.rs (line 42)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let mut args = env::args().skip(1);
7    let action = args.next().unwrap_or_else(|| "status".to_string());
8
9    let socket =
10        env::var("FALCORN_CONTROL_SOCKET").unwrap_or_else(|_| DEFAULT_CONTROL_SOCKET.to_string());
11    let token = env::var("FALCORN_CONTROL_TOKEN").ok();
12    let client_name = env::var("FALCORN_CONTROL_CLIENT").ok();
13
14    let mut builder = ControlClient::builder(socket);
15    if let Some(token) = token {
16        builder = builder.auth_token(token);
17    }
18    if let Some(client_name) = client_name {
19        builder = builder.client_name(client_name);
20    }
21
22    let mut client = builder.connect()?;
23
24    match action.as_str() {
25        "status" => {
26            let status = client.get_status()?;
27            println!("{:#?}", status);
28        }
29        "workers" => {
30            let workers = client.get_workers()?;
31            println!("{:#?}", workers);
32        }
33        "show-config" => {
34            let config = client.show_config()?;
35            println!("{}", config);
36        }
37        "scale" => {
38            let workers = args
39                .next()
40                .ok_or("scale requires worker count")?
41                .parse::<usize>()?;
42            let message = client.scale_to(workers)?;
43            println!("{}", message);
44        }
45        "restart" => {
46            let id = args.next().and_then(|value| value.parse::<u32>().ok());
47            let force = args.any(|value| value == "--force");
48            let message = client.restart_worker(id, !force)?;
49            println!("{}", message);
50        }
51        "shutdown" => {
52            let force = args.any(|value| value == "--force");
53            let message = client.shutdown(!force)?;
54            println!("{}", message);
55        }
56        "reload" => {
57            let mut path = None;
58            let mut rolling = true;
59            for value in args {
60                if value == "--no-rolling" {
61                    rolling = false;
62                } else if value.starts_with("--path=") {
63                    path = value.split('=').nth(1).map(|s| s.to_string());
64                } else if path.is_none() {
65                    path = Some(value);
66                }
67            }
68            let message = client.reload_config(path, rolling)?;
69            println!("{}", message);
70        }
71        other => {
72            eprintln!(
73                "Unknown action: {} (use status|workers|show-config|scale|restart|shutdown|reload)",
74                other
75            );
76        }
77    }
78
79    Ok(())
80}
Source

pub fn restart_worker( &mut self, id: Option<u32>, graceful: bool, ) -> Result<String>

Examples found in repository?
examples/control.rs (line 48)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let mut args = env::args().skip(1);
7    let action = args.next().unwrap_or_else(|| "status".to_string());
8
9    let socket =
10        env::var("FALCORN_CONTROL_SOCKET").unwrap_or_else(|_| DEFAULT_CONTROL_SOCKET.to_string());
11    let token = env::var("FALCORN_CONTROL_TOKEN").ok();
12    let client_name = env::var("FALCORN_CONTROL_CLIENT").ok();
13
14    let mut builder = ControlClient::builder(socket);
15    if let Some(token) = token {
16        builder = builder.auth_token(token);
17    }
18    if let Some(client_name) = client_name {
19        builder = builder.client_name(client_name);
20    }
21
22    let mut client = builder.connect()?;
23
24    match action.as_str() {
25        "status" => {
26            let status = client.get_status()?;
27            println!("{:#?}", status);
28        }
29        "workers" => {
30            let workers = client.get_workers()?;
31            println!("{:#?}", workers);
32        }
33        "show-config" => {
34            let config = client.show_config()?;
35            println!("{}", config);
36        }
37        "scale" => {
38            let workers = args
39                .next()
40                .ok_or("scale requires worker count")?
41                .parse::<usize>()?;
42            let message = client.scale_to(workers)?;
43            println!("{}", message);
44        }
45        "restart" => {
46            let id = args.next().and_then(|value| value.parse::<u32>().ok());
47            let force = args.any(|value| value == "--force");
48            let message = client.restart_worker(id, !force)?;
49            println!("{}", message);
50        }
51        "shutdown" => {
52            let force = args.any(|value| value == "--force");
53            let message = client.shutdown(!force)?;
54            println!("{}", message);
55        }
56        "reload" => {
57            let mut path = None;
58            let mut rolling = true;
59            for value in args {
60                if value == "--no-rolling" {
61                    rolling = false;
62                } else if value.starts_with("--path=") {
63                    path = value.split('=').nth(1).map(|s| s.to_string());
64                } else if path.is_none() {
65                    path = Some(value);
66                }
67            }
68            let message = client.reload_config(path, rolling)?;
69            println!("{}", message);
70        }
71        other => {
72            eprintln!(
73                "Unknown action: {} (use status|workers|show-config|scale|restart|shutdown|reload)",
74                other
75            );
76        }
77    }
78
79    Ok(())
80}
Source

pub fn shutdown(&mut self, graceful: bool) -> Result<String>

Examples found in repository?
examples/control.rs (line 53)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let mut args = env::args().skip(1);
7    let action = args.next().unwrap_or_else(|| "status".to_string());
8
9    let socket =
10        env::var("FALCORN_CONTROL_SOCKET").unwrap_or_else(|_| DEFAULT_CONTROL_SOCKET.to_string());
11    let token = env::var("FALCORN_CONTROL_TOKEN").ok();
12    let client_name = env::var("FALCORN_CONTROL_CLIENT").ok();
13
14    let mut builder = ControlClient::builder(socket);
15    if let Some(token) = token {
16        builder = builder.auth_token(token);
17    }
18    if let Some(client_name) = client_name {
19        builder = builder.client_name(client_name);
20    }
21
22    let mut client = builder.connect()?;
23
24    match action.as_str() {
25        "status" => {
26            let status = client.get_status()?;
27            println!("{:#?}", status);
28        }
29        "workers" => {
30            let workers = client.get_workers()?;
31            println!("{:#?}", workers);
32        }
33        "show-config" => {
34            let config = client.show_config()?;
35            println!("{}", config);
36        }
37        "scale" => {
38            let workers = args
39                .next()
40                .ok_or("scale requires worker count")?
41                .parse::<usize>()?;
42            let message = client.scale_to(workers)?;
43            println!("{}", message);
44        }
45        "restart" => {
46            let id = args.next().and_then(|value| value.parse::<u32>().ok());
47            let force = args.any(|value| value == "--force");
48            let message = client.restart_worker(id, !force)?;
49            println!("{}", message);
50        }
51        "shutdown" => {
52            let force = args.any(|value| value == "--force");
53            let message = client.shutdown(!force)?;
54            println!("{}", message);
55        }
56        "reload" => {
57            let mut path = None;
58            let mut rolling = true;
59            for value in args {
60                if value == "--no-rolling" {
61                    rolling = false;
62                } else if value.starts_with("--path=") {
63                    path = value.split('=').nth(1).map(|s| s.to_string());
64                } else if path.is_none() {
65                    path = Some(value);
66                }
67            }
68            let message = client.reload_config(path, rolling)?;
69            println!("{}", message);
70        }
71        other => {
72            eprintln!(
73                "Unknown action: {} (use status|workers|show-config|scale|restart|shutdown|reload)",
74                other
75            );
76        }
77    }
78
79    Ok(())
80}
Source

pub fn reload_config( &mut self, path: Option<String>, rolling: bool, ) -> Result<String>

Examples found in repository?
examples/control.rs (line 68)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let mut args = env::args().skip(1);
7    let action = args.next().unwrap_or_else(|| "status".to_string());
8
9    let socket =
10        env::var("FALCORN_CONTROL_SOCKET").unwrap_or_else(|_| DEFAULT_CONTROL_SOCKET.to_string());
11    let token = env::var("FALCORN_CONTROL_TOKEN").ok();
12    let client_name = env::var("FALCORN_CONTROL_CLIENT").ok();
13
14    let mut builder = ControlClient::builder(socket);
15    if let Some(token) = token {
16        builder = builder.auth_token(token);
17    }
18    if let Some(client_name) = client_name {
19        builder = builder.client_name(client_name);
20    }
21
22    let mut client = builder.connect()?;
23
24    match action.as_str() {
25        "status" => {
26            let status = client.get_status()?;
27            println!("{:#?}", status);
28        }
29        "workers" => {
30            let workers = client.get_workers()?;
31            println!("{:#?}", workers);
32        }
33        "show-config" => {
34            let config = client.show_config()?;
35            println!("{}", config);
36        }
37        "scale" => {
38            let workers = args
39                .next()
40                .ok_or("scale requires worker count")?
41                .parse::<usize>()?;
42            let message = client.scale_to(workers)?;
43            println!("{}", message);
44        }
45        "restart" => {
46            let id = args.next().and_then(|value| value.parse::<u32>().ok());
47            let force = args.any(|value| value == "--force");
48            let message = client.restart_worker(id, !force)?;
49            println!("{}", message);
50        }
51        "shutdown" => {
52            let force = args.any(|value| value == "--force");
53            let message = client.shutdown(!force)?;
54            println!("{}", message);
55        }
56        "reload" => {
57            let mut path = None;
58            let mut rolling = true;
59            for value in args {
60                if value == "--no-rolling" {
61                    rolling = false;
62                } else if value.starts_with("--path=") {
63                    path = value.split('=').nth(1).map(|s| s.to_string());
64                } else if path.is_none() {
65                    path = Some(value);
66                }
67            }
68            let message = client.reload_config(path, rolling)?;
69            println!("{}", message);
70        }
71        other => {
72            eprintln!(
73                "Unknown action: {} (use status|workers|show-config|scale|restart|shutdown|reload)",
74                other
75            );
76        }
77    }
78
79    Ok(())
80}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.