Fully Automated - 100% Backpressure - Pipeline runner ๐Ÿƒ for AI workflows. ๐Ÿš€

Commit 2fb75318

2fb753185e8fMerged

Scott Nixon <[email protected]> ยท 9 months ago ยท 1 file ยท ~1 modified

Description

[attractor-e7q] Initialize DB pool in main.rs and inject into Leptos context

  • Initialize SQLite database pool via db::init_db() on server startup
  • Remove hardcoded single-project DocumentWatcher initialization
  • Restructure AppState to use db and per-project watchers map
  • Inject SqlitePool into Leptos server function context via provide_context
  • Expected breakage in documents.rs (fixed in attractor-3jj)

Details

Commit
2fb753185e8f
Parent
8baac2756b13

crates/attractor-web/src/main.rsmodifiedView file

@@ -5,9 +5,8 @@
55 use leptos::config::get_configuration;
66 use leptos_axum::{generate_route_list, LeptosRoutes};
77 use attractor_web::App;
8- use attractor_web::server::documents::DocumentWatcher;
9- use std::path::PathBuf;
10- use std::sync::Arc;
8+ use std::sync::{Arc, Mutex};
9+ use std::collections::HashMap;
1110
1211 tracing_subscriber::fmt::init();
1312
@@ -16,18 +15,16 @@
1615 let leptos_options = conf.leptos_options;
1716 let routes = generate_route_list(App);
1817
19- // Initialize file watcher for .attractor/ directory
20- let attractor_dir = PathBuf::from(".attractor");
21- let doc_watcher = Arc::new(
22- DocumentWatcher::new(attractor_dir.clone())
23- .expect("Failed to start document file watcher"),
24- );
18+ // Initialize SQLite database
19+ let db = attractor_web::server::db::init_db()
20+ .await
21+ .expect("Failed to initialize database");
2522
2623 let terminal_sessions = attractor_web::server::terminal::TerminalSessions::default();
2724
2825 let app_state = attractor_web::server::AppState {
29- doc_watcher: doc_watcher.clone(),
30- attractor_dir,
26+ db: db.clone(),
27+ watchers: Arc::new(Mutex::new(HashMap::new())),
3128 terminal_sessions,
3229 };
3330
@@ -52,8 +49,13 @@
5249 .leptos_routes_with_context(
5350 &leptos_options,
5451 routes,
55- move || {},
5652 {
53+ let pool = db.clone();
54+ move || {
55+ leptos::prelude::provide_context(pool.clone());
56+ }
57+ },
58+ {
5759 let leptos_options = leptos_options.clone();
5860 move || shell(leptos_options.clone())
5961 },