[feat] modularized backend with plugin architecture, added module-api
, module-host
, and summarizer
crates, and integrated dynamic module loading into main.rs
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
#[tokio::main]
|
||||
#[tokio::main(flavor = "multi_thread")]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
// Basic tracing setup (adjust as needed)
|
||||
// Tracing setup
|
||||
tracing_subscriber::registry()
|
||||
.with(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env()
|
||||
@@ -11,9 +11,35 @@ async fn main() -> anyhow::Result<()> {
|
||||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
|
||||
// TODO: invoke your API server bootstrap here.
|
||||
// For example, if you have a function like `owly-news-api::run_server().await`
|
||||
// call it here. This is just a placeholder:
|
||||
tracing::info!("owly-news app starting...");
|
||||
// Limit worker threads for CPU control (can be tuned via env)
|
||||
// Note: When using #[tokio::main], configure via env TOKIO_WORKER_THREADS.
|
||||
// Alternatively, build a Runtime manually for stricter control.
|
||||
if let Ok(threads) = std::env::var("TOKIO_WORKER_THREADS") {
|
||||
tracing::warn!(
|
||||
"TOKIO_WORKER_THREADS is set to {threads}, ensure it matches deployment requirements"
|
||||
);
|
||||
} else {
|
||||
// Provide a sane default via env if not set
|
||||
let default_threads = std::cmp::max(1, num_cpus::get_physical() / 2);
|
||||
unsafe { std::env::set_var("TOKIO_WORKER_THREADS", default_threads.to_string()); }
|
||||
tracing::info!("Defaulting worker threads to {}", default_threads);
|
||||
}
|
||||
|
||||
// Example: lazily load and invoke the "summarizer" module when needed
|
||||
let host = owly_news_module_host::ModuleHost::default();
|
||||
|
||||
// Simulate an on-demand call (e.g., from an HTTP handler)
|
||||
let summarizer = host.get("summarizer").await?;
|
||||
let resp = summarizer.invoke_json(
|
||||
"summarize",
|
||||
serde_json::json!({
|
||||
"text": "Rust enables fearless concurrency with strong guarantees over memory safety.",
|
||||
"ratio": 0.3
|
||||
}),
|
||||
)?;
|
||||
tracing::info!(?resp, "summarizer response");
|
||||
|
||||
// TODO: wire this into your API routes/handlers, using the host.get("<module>").await when needed.
|
||||
tracing::info!("owly-news daemon running");
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user