Listening to the shaggs!
This commit is contained in:
1 parent
238cd9f2da
commit
9f86d53d11
9 files changed
+69
-66
No files matched your search
+27
-13
@@ -19,11 +19,19 @@ use rusqlite::Connection;
|
||||
|
||||
use crate::events::Event;
|
||||
use crate::util::{CustomResult, Error};
|
||||
use crate::webui::worker::worker_loop;
|
||||
use crate::webui::worker::{bob, event_processor_loop};
|
||||
|
||||
mod views;
|
||||
mod worker;
|
||||
|
||||
struct Service {}
|
||||
|
||||
impl Service {
|
||||
fn get_users(self) -> Vec<String> {
|
||||
vec!["to".to_string(), "foo".to_string()]
|
||||
}
|
||||
}
|
||||
|
||||
struct MiniJinjaRenderer {
|
||||
tmpl_env: web::Data<minijinja_autoreload::AutoReloader>,
|
||||
}
|
||||
@@ -58,12 +66,8 @@ impl FromRequest for MiniJinjaRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn web_ui_main(conn: &mut Connection,
|
||||
port: u16,
|
||||
enable_template_autoreload: bool) -> CustomResult<()> {
|
||||
// The closure is invoked every time the environment is outdated to recreate it.
|
||||
let tmpl_reloader = AutoReloader::new(move |notifier| {
|
||||
fn create_auto_reloader(enable_template_autoreload: bool) -> AutoReloader {
|
||||
AutoReloader::new(move |notifier| {
|
||||
let mut env: minijinja::Environment<'static> = minijinja::Environment::new();
|
||||
|
||||
let tmpl_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("resources/templates");
|
||||
@@ -75,7 +79,15 @@ pub async fn web_ui_main(conn: &mut Connection,
|
||||
}
|
||||
env.set_source(minijinja::Source::from_path(tmpl_path));
|
||||
Ok(env)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn web_ui_main(conn: &mut Connection,
|
||||
port: u16,
|
||||
enable_template_autoreload: bool) -> CustomResult<()> {
|
||||
// The closure is invoked every time the environment is outdated to recreate it.
|
||||
let tmpl_reloader = create_auto_reloader(enable_template_autoreload);
|
||||
|
||||
let (s, r) = async_channel::unbounded::<Event>();
|
||||
|
||||
@@ -97,17 +109,19 @@ pub async fn web_ui_main(conn: &mut Connection,
|
||||
.wrap(ErrorHandlers::new().handler(StatusCode::NOT_FOUND, not_found))
|
||||
.wrap(Logger::default())
|
||||
})
|
||||
.workers(2)
|
||||
.bind(("0.0.0.0", port))
|
||||
.unwrap();
|
||||
.workers(2)
|
||||
.bind(("0.0.0.0", port))
|
||||
.unwrap();
|
||||
|
||||
let t1 = server.run().fuse();
|
||||
let t2 = worker_loop(conn, r).fuse();
|
||||
pin_mut!(t1, t2);
|
||||
let t2 = event_processor_loop(conn, r).fuse();
|
||||
let t3 = bob().fuse();
|
||||
pin_mut!(t1, t2, t3);
|
||||
|
||||
select! {
|
||||
x = t1 => x.map_err(Error::IOError),
|
||||
y = t2 => y,
|
||||
z = t3 => z,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user