Skip to main content

ControlClientBuilder

Struct ControlClientBuilder 

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

Implementations§

Source§

impl ControlClientBuilder

Source

pub fn new(socket: impl Into<String>) -> Self

Source

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}
Source

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}
Source

pub fn read_timeout(self, timeout: Duration) -> Self

Source

pub fn write_timeout(self, timeout: Duration) -> Self

Source

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

Source§

fn clone(&self) -> ControlClientBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ControlClientBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.