pub struct ControlClientBuilder { /* private fields */ }Implementations§
Source§impl ControlClientBuilder
impl ControlClientBuilder
pub fn new(socket: impl Into<String>) -> Self
Sourcepub fn auth_token(self, token: impl Into<String>) -> Self
pub fn auth_token(self, token: impl Into<String>) -> Self
Examples found in repository?
examples/control.rs (line 16)
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}Sourcepub fn client_name(self, name: impl Into<String>) -> Self
pub fn client_name(self, name: impl Into<String>) -> Self
Examples found in repository?
examples/control.rs (line 19)
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}pub fn read_timeout(self, timeout: Duration) -> Self
pub fn write_timeout(self, timeout: Duration) -> Self
Sourcepub fn connect(self) -> Result<ControlClient>
pub fn connect(self) -> Result<ControlClient>
Examples found in repository?
examples/control.rs (line 22)
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}Trait Implementations§
Source§impl Clone for ControlClientBuilder
impl Clone for ControlClientBuilder
Source§fn clone(&self) -> ControlClientBuilder
fn clone(&self) -> ControlClientBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ControlClientBuilder
impl RefUnwindSafe for ControlClientBuilder
impl Send for ControlClientBuilder
impl Sync for ControlClientBuilder
impl Unpin for ControlClientBuilder
impl UnsafeUnpin for ControlClientBuilder
impl UnwindSafe for ControlClientBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more