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
use super::AsyncSpawable;
use scsys::{prelude::Logger, BoxResult};
pub trait ApplicationSpec: Default {
type Cnf: Clone;
type Ctx;
type Msg;
fn context(&self) -> &Self::Ctx;
fn messages(&self) -> &Vec<Self::Msg>;
fn settings(&self) -> &Self::Cnf;
}
pub trait ApplicationLoggerSpec: ApplicationSpec {
fn with_tracing(&self, level: Option<&str>) -> BoxResult<&Self> {
let mut logger = Logger::new(level.unwrap_or("info").to_string());
logger.setup(None);
tracing_subscriber::fmt::init();
tracing::info!("Successfully initiated the tracing protocol...");
Ok(self)
}
}
#[async_trait::async_trait]
pub trait AsyncApplicationSpawner: AsyncSpawable {
async fn graceful_shutdown(&self) {
tokio::signal::ctrl_c()
.await
.expect("Failed to terminate the runtime...");
tracing::info!("Terminating the application and connected services...");
}
}
#[cfg(feature = "cli")]
#[cfg(not(feature = "wasm"))]
pub trait CommandLineInterface: clap::Parser {}