Skip to content

Commit

Permalink
Use traing in notificox
Browse files Browse the repository at this point in the history
  • Loading branch information
GamePad64 committed Dec 17, 2024
1 parent 44f03a3 commit b5a7aa2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 48 deletions.
33 changes: 2 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions notifico-core/src/credentials/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::error::EngineError;
use async_trait::async_trait;
use std::borrow::Cow;
use std::collections::HashMap;
use tracing::info;
use uuid::Uuid;

#[derive(Eq, PartialEq, Hash, Debug)]
Expand All @@ -16,6 +17,11 @@ pub struct MemoryCredentialStorage(HashMap<CredentialKey<'static>, RawCredential

impl MemoryCredentialStorage {
pub fn add_credential(&mut self, project: Uuid, name: String, credential: RawCredential) {
info!(
credential.project = project.to_string(),
credential.name = name,
"Added credential"
);
self.0.insert(
CredentialKey {
project,
Expand Down
4 changes: 2 additions & 2 deletions notificox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ json5 = "0.4.1"
flume = "0.11.1"
dotenvy = "0.15.7"
uuid = { workspace = true }
log = "0.4.22"
env_logger = "0.11.5"
url = { workspace = true }
reqwest = { workspace = true }
tracing-subscriber = "0.3.19"
tracing = "0.1.41"
38 changes: 23 additions & 15 deletions notificox/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use clap::{Parser, Subcommand};
use log::info;
use notifico_attachment::AttachmentPlugin;
use notifico_core::contact::RawContact;
use notifico_core::credentials::memory::MemoryCredentialStorage;
Expand All @@ -22,9 +21,15 @@ use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;
use tokio::task::JoinSet;
use tracing::info;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{fmt, EnvFilter};
use url::Url;
use uuid::Uuid;

const SINGLETON_CREDENTIAL_NAME: &str = "default";

#[derive(Parser, Debug)]
struct Cli {
#[command(subcommand)]
Expand Down Expand Up @@ -66,10 +71,13 @@ async fn main() {
let _ = dotenvy::dotenv();

if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "notificox=info,warn");
std::env::set_var("RUST_LOG", "notificox=info,notifico_core=info,warn");
}

env_logger::init();
tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_default_env())
.init();

let cli = Cli::parse();

Expand All @@ -90,7 +98,7 @@ async fn main() {
let mut credentials = MemoryCredentialStorage::default();
credentials.add_credential(
Uuid::nil(),
"notificox".to_string(),
SINGLETON_CREDENTIAL_NAME.to_string(),
credential.clone(),
);
Arc::new(credentials)
Expand Down Expand Up @@ -149,16 +157,21 @@ async fn main() {
}

let transport_name = credential.transport;
let step = SerializedStep(
json!({ "step": transport_registry.get_step(&transport_name).unwrap(), "credential": "notificox" })
.as_object()
.cloned()
.unwrap(),
);
let step = json!({
"step": transport_registry.get_step(&transport_name).unwrap(),
"credential": SINGLETON_CREDENTIAL_NAME
});
let step = SerializedStep(step.as_object().cloned().unwrap());
pipeline.steps.push(step);

pipeline
};

info!(
"Running pipeline: {}",
serde_json::to_string_pretty(&pipeline).unwrap()
);

let contacts: Vec<RawContact> = contacts.iter().map(|s| s.parse().unwrap()).collect();

let recipient = Recipient {
Expand All @@ -174,11 +187,6 @@ async fn main() {
context: Default::default(),
};

info!(
"Running pipeline: {}",
serde_json::to_string_pretty(&pipeline).unwrap()
);

let (pipelines_tx, pipelines_rx) = flume::unbounded();
let pipelines_tx = Arc::new(pipelines_tx);

Expand Down

0 comments on commit b5a7aa2

Please sign in to comment.