Added simple tracing
This commit is contained in:
parent
6816a69706
commit
3918a2086b
4 changed files with 34 additions and 12 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -260,6 +260,8 @@ dependencies = [
|
|||
"serde",
|
||||
"surrealdb",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -8,3 +8,5 @@ futures = "0.3.30"
|
|||
serde = { version = "1.0.207", features = ["derive"] }
|
||||
surrealdb = "1.5.4"
|
||||
tokio = { version = "1.39.2", features = ["macros", "rt-multi-thread"] }
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = "0.3.18"
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,16 +1,22 @@
|
|||
use bcup::{models::ServerConfiguration, services::BackupServerService};
|
||||
use futures::StreamExt;
|
||||
use surrealdb::{engine::remote::ws::Ws, Notification, Result, Surreal};
|
||||
use tracing::{debug, info, Level};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> surrealdb::Result<()> {
|
||||
let db = Surreal::new::<Ws>("127.0.0.1:8000").await?;
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(Level::DEBUG)
|
||||
.init();
|
||||
|
||||
let db = Surreal::new::<Ws>("127.0.0.1:8000").await?;
|
||||
db.use_ns("test").use_db("test").await?;
|
||||
|
||||
info!("Connected to db");
|
||||
|
||||
let service = BackupServerService::new(db.clone());
|
||||
|
||||
println!("Prepared to listen");
|
||||
info!("Listening on table `rest_server` for changes");
|
||||
let mut stream = db.select("rest_server").live().await?;
|
||||
while let Some(result) = stream.next().await {
|
||||
handle(result, &service).await;
|
||||
|
@ -19,7 +25,7 @@ async fn main() -> surrealdb::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
async fn handle(result: Result<Notification<ServerConfiguration>>, service: &BackupServerService) {
|
||||
println!("Something to handle");
|
||||
debug!("Handeling incoming changes");
|
||||
match result {
|
||||
Ok(notification) => {
|
||||
let conf = ¬ification.data;
|
||||
|
@ -32,7 +38,7 @@ async fn handle(result: Result<Notification<ServerConfiguration>>, service: &Bac
|
|||
}
|
||||
|
||||
async fn process_new_item(conf: &ServerConfiguration, service: &BackupServerService) {
|
||||
println!("The following item has to be processed {:?}", conf);
|
||||
debug!("Processing the following item id:`{:?}`", &conf.id);
|
||||
|
||||
service.spawn_restic_container(conf.directory.clone()).await;
|
||||
service
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use surrealdb::opt::PatchOp;
|
||||
use surrealdb::{opt::PatchOp, Error};
|
||||
use tracing::{debug, error};
|
||||
|
||||
use crate::{
|
||||
models::{Record, ServerConfiguration},
|
||||
|
@ -14,20 +15,31 @@ impl BackupServerService {
|
|||
Self { db }
|
||||
}
|
||||
pub async fn mark_data_as_processed(&self, conf: &ServerConfiguration) {
|
||||
println!("Updating status on item id:{:?}", conf.id);
|
||||
let updated: Option<Record> = self
|
||||
debug!("Updating status on item id:{:?}", conf.id);
|
||||
//let updated: Option<Record> = self
|
||||
let result: Result<Option<Record>, Error> = self
|
||||
.db
|
||||
.update(&conf.id)
|
||||
.patch(PatchOp::replace("/state/now", "processed"))
|
||||
.await
|
||||
.unwrap();
|
||||
dbg!(updated);
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(_record) => {
|
||||
debug!("Status for item id:`{:?}` has been updated", &conf.id);
|
||||
}
|
||||
Err(err) => {
|
||||
error!(
|
||||
"Could not update status for item {:?}. Err:{:?}",
|
||||
&conf.id, err
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn spawn_restic_container(&self, path: String) {
|
||||
println!("[fake] Spawning container for path {:?}", path);
|
||||
debug!("[fake] Spawning container for path {:?}", path);
|
||||
}
|
||||
pub async fn add_proxy_configuration(&self, path: String) {
|
||||
println!("[fake] Creating caddy configuration {:?}", path);
|
||||
debug!("[fake] Creating caddy configuration {:?}", path);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue