This repository was archived by the owner on Jul 2, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmod.rs
85 lines (81 loc) · 2.99 KB
/
mod.rs
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
pub mod build;
pub mod code;
pub mod config;
pub mod init;
pub mod list;
pub mod log;
pub mod new;
pub mod preview;
pub mod project;
pub mod ps;
pub mod restart;
pub mod start;
pub mod status;
pub mod stop;
pub mod tail;
pub mod ui;
macro_rules! event_handler {
($client:expr, $service:expr, $config_file_path:expr) => {
tokio::spawn(async move {
let request = tonic::Request::new(EventsRequest {
service: $service,
config_file_path: $config_file_path,
});
let response = $client.events(request).await?;
let mut stream = response.into_inner();
while let Some(message) = stream.message().await? {
match message.event.as_str() {
SERVICE_STARTING => {
println!("-> Starting {} ...", message.service.bright_green());
}
SERVICE_BUILDING => {
println!("-> Building {} ...", message.service.bright_green());
}
SERVICE_CRASHED => {
println!("{} has crashed", message.service.bright_green());
}
SERVICE_ERROR => {
println!(
"{} has encountered an error",
message.service.bright_green()
);
println!("{}", message.output);
}
SERVICE_RESTARTING => {
println!("-> Restarting {} ...", message.service.bright_green());
}
SERVICE_STOPPING => {
println!("-> Stopping {} ...", message.service.bright_green());
}
SERVICE_LOGS => {
let prefix = format!("{} | ", message.service.cyan());
print!("{}{}", prefix, message.output);
}
SERVICE_SETUP_ENV => {
println!(
"-> Setting up environment for {} ...",
message.service.bright_green()
);
let prefix = format!("{} | ", message.service.cyan());
println!("{} {}", prefix, message.output);
}
ALL_SERVICES_BUILT => {
println!("-> All services have been built");
break;
}
ALL_SERVICES_RESTARTED => {
println!("-> All services have been restarted");
break;
}
ALL_SERVICES_STOPPED => {
println!("-> All services have been stopped");
break;
}
_ => {}
}
}
Ok::<(), Error>(())
})
};
}
pub(crate) use event_handler;