init worker
This commit is contained in:
27
notes-worker/Cargo.toml
Normal file
27
notes-worker/Cargo.toml
Normal file
@@ -0,0 +1,27 @@
|
||||
[package]
|
||||
name = "notes-worker"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.100"
|
||||
async-nats = "0.45.0"
|
||||
notes-domain = { path = "../notes-domain" }
|
||||
notes-infra = { path = "../notes-infra" }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.146"
|
||||
tokio = { version = "1.48.0", features = ["full"] }
|
||||
chrono = { version = "0.4.42", features = ["serde"] }
|
||||
sqlx = { version = "0.8.6", features = [
|
||||
"sqlite",
|
||||
"runtime-tokio",
|
||||
"chrono",
|
||||
"migrate",
|
||||
] }
|
||||
thiserror = "2.0.17"
|
||||
bytes = "1.11.0"
|
||||
futures-util = "0.3.31"
|
||||
async-trait = "0.1.89"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3.22", features = ["env-filter"] }
|
||||
dotenvy = "0.15.7"
|
||||
25
notes-worker/src/config.rs
Normal file
25
notes-worker/src/config.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub broker_url: String,
|
||||
pub database_url: String,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
broker_url: "nats://localhost:4222".to_string(),
|
||||
database_url: "sqlite::memory:".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_env() -> Self {
|
||||
let _ = dotenvy::dotenv();
|
||||
|
||||
Self {
|
||||
broker_url: std::env::var("BROKER_URL").unwrap_or("nats://localhost:4222".to_string()),
|
||||
database_url: std::env::var("DATABASE_URL").unwrap_or("sqlite::memory:".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
16
notes-worker/src/main.rs
Normal file
16
notes-worker/src/main.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use notes_infra::{DatabaseConfig, create_pool};
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
mod config;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let config = Config::from_env();
|
||||
let nats_client = async_nats::connect(config.broker_url).await?;
|
||||
let db_config = DatabaseConfig::new(config.database_url);
|
||||
let db_pool = create_pool(&db_config).await?;
|
||||
|
||||
// subscribe to jobs and process them
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user