Release 0.1.0

This commit is contained in:
Fasterino
2025-10-31 04:27:42 +03:00
commit 6fe2f12b8e
30 changed files with 2031 additions and 0 deletions

24
src/service.rs Normal file
View File

@@ -0,0 +1,24 @@
use std::sync::Arc;
use crate::{context::Context, log_err, log_warn, settings::Result};
#[async_trait::async_trait]
pub trait Service: Sync + Send + 'static {
fn new() -> Arc<Self>
where
Self: Sized;
async fn run(self: Arc<Self>, context: Context) {
let mut code = 0;
if let Err(e) = self.clone().run_inner(context.clone()).await {
log_err!("{} error: {}", self.service_name(), e);
code = 1;
}
log_warn!("{} stopped: exiting...", self.service_name());
std::process::exit(code);
}
async fn run_inner(self: Arc<Self>, context: Context) -> Result<()>;
fn service_name(&self) -> &'static str;
}