aboutsummaryrefslogtreecommitdiffstats
path: root/crates/aggregator/src/state.rs
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2025-08-16 14:13:14 +0200
committerrtkay123 <dev@kanjala.com>2025-08-16 14:13:14 +0200
commit70a148dd86be9c8ccc56e1fce232262475aa3158 (patch)
tree51214ab651215ef94a8554039cc953042b043cf6 /crates/aggregator/src/state.rs
parentbf4a2b8b0a04f0cb682db84a835fe7c57d8526bc (diff)
downloadwarden-70a148dd86be9c8ccc56e1fce232262475aa3158.tar.bz2
warden-70a148dd86be9c8ccc56e1fce232262475aa3158.zip
feat(aggregator): write evaluation
Diffstat (limited to 'crates/aggregator/src/state.rs')
-rw-r--r--crates/aggregator/src/state.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/crates/aggregator/src/state.rs b/crates/aggregator/src/state.rs
new file mode 100644
index 0000000..ac4f574
--- /dev/null
+++ b/crates/aggregator/src/state.rs
@@ -0,0 +1,42 @@
+use sqlx::PgPool;
+use std::{ops::Deref, sync::Arc};
+
+use async_nats::jetstream::Context;
+use warden_stack::{Configuration, cache::RedisManager};
+
+use crate::cnfg::LocalConfig;
+
+#[derive(Clone)]
+pub struct Services {
+ pub jetstream: Context,
+ pub cache: RedisManager,
+ pub postgres: PgPool,
+}
+
+#[derive(Clone)]
+pub struct AppState {
+ pub services: Services,
+ pub config: LocalConfig,
+}
+
+#[derive(Clone)]
+pub struct AppHandle(pub Arc<AppState>);
+
+impl Deref for AppHandle {
+ type Target = Arc<AppState>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+impl AppState {
+ pub async fn create(
+ services: Services,
+ configuration: &Configuration,
+ ) -> anyhow::Result<AppHandle> {
+ let config = serde_json::from_value(configuration.misc.clone())?;
+
+ Ok(AppHandle(Arc::new(Self { services, config })))
+ }
+}