init worker
This commit is contained in:
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