More linting.
This commit is contained in:
1 parent
f4170610b0
commit
feaab2e843
5 files changed
+26
-33
No files matched your search
+17
-17
@@ -251,14 +251,14 @@ fn process_process_events_command_line(
|
||||
}
|
||||
|
||||
fn process_run_wui_command_line(
|
||||
connFact: SQLiteConnectionFactory,
|
||||
conn_fact: SQLiteConnectionFactory,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing run wui command line {:?}.", m);
|
||||
let port = m.get_one::<u16>("port").unwrap_or(&2222);
|
||||
let enable_template_autoreload = m.get_flag("enable-template-autoreload");
|
||||
logic.run_webui(connFact, *port, enable_template_autoreload)
|
||||
logic.run_webui(conn_fact, *port, enable_template_autoreload)
|
||||
}
|
||||
|
||||
fn process_securities_command_line(
|
||||
@@ -290,26 +290,26 @@ fn process_events_command_line(
|
||||
}
|
||||
|
||||
fn process_wui_command_line(
|
||||
connFact: SQLiteConnectionFactory,
|
||||
conn_fact: SQLiteConnectionFactory,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing wui command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("run", run_wui_match)) => {
|
||||
process_run_wui_command_line(connFact, run_wui_match, logic)
|
||||
process_run_wui_command_line(conn_fact, run_wui_match, logic)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn process_command_line(
|
||||
connFact: SQLiteConnectionFactory,
|
||||
conn_fact: SQLiteConnectionFactory,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing command line {:?}.", m);
|
||||
let mut conn = connFact.connection()?;
|
||||
let mut conn = conn_fact.connection()?;
|
||||
match m.subcommand() {
|
||||
Some(("users", user_match)) => process_user_command_line(&mut conn, user_match, logic),
|
||||
Some(("securities", securities_match)) => {
|
||||
@@ -318,7 +318,7 @@ fn process_command_line(
|
||||
Some(("events", events_match)) => {
|
||||
process_events_command_line(&mut conn, events_match, logic)
|
||||
}
|
||||
Some(("wui", wui_match)) => process_wui_command_line(connFact, wui_match, logic),
|
||||
Some(("wui", wui_match)) => process_wui_command_line(conn_fact, wui_match, logic),
|
||||
_ => {
|
||||
println!("Received un parsable command. {:?}", m.subcommand());
|
||||
unreachable!();
|
||||
@@ -437,7 +437,7 @@ mod cli_test {
|
||||
]);
|
||||
let mut logic = TestCommandLineLogic::new();
|
||||
let mut conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(SQLiteConnectionFactory::inMemory(), &m, &mut logic)?;
|
||||
process_command_line(SQLiteConnectionFactory::in_memory(), &m, &mut logic)?;
|
||||
assert_eq!(logic.create_user_count, 1);
|
||||
Ok(())
|
||||
}
|
||||
@@ -448,7 +448,7 @@ mod cli_test {
|
||||
let m = cmd.get_matches_from(vec!["test", "users", "ls"]);
|
||||
let mut logic = TestCommandLineLogic::new();
|
||||
let mut conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(SQLiteConnectionFactory::inMemory(), &m, &mut logic)?;
|
||||
process_command_line(SQLiteConnectionFactory::in_memory(), &m, &mut logic)?;
|
||||
assert_eq!(logic.list_user_count, 1);
|
||||
Ok(())
|
||||
}
|
||||
@@ -459,7 +459,7 @@ mod cli_test {
|
||||
let m = cmd.get_matches_from(vec!["test", "securities", "ls"]);
|
||||
let mut logic = TestCommandLineLogic::new();
|
||||
let mut conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(SQLiteConnectionFactory::inMemory(), &m, &mut logic)?;
|
||||
process_command_line(SQLiteConnectionFactory::in_memory(), &m, &mut logic)?;
|
||||
assert_eq!(logic.list_securities_count, 1);
|
||||
Ok(())
|
||||
}
|
||||
@@ -470,7 +470,7 @@ mod cli_test {
|
||||
let m = cmd.get_matches_from(vec!["test", "events", "process", "/dev/null"]);
|
||||
let mut logic = TestCommandLineLogic::new();
|
||||
let mut conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(SQLiteConnectionFactory::inMemory(), &m, &mut logic)?;
|
||||
process_command_line(SQLiteConnectionFactory::in_memory(), &m, &mut logic)?;
|
||||
assert_eq!(logic.process_events_count, 1);
|
||||
Ok(())
|
||||
}
|
||||
@@ -481,7 +481,7 @@ mod cli_test {
|
||||
let m = cmd.get_matches_from(vec!["test", "wui", "run"]);
|
||||
let mut logic = TestCommandLineLogic::new();
|
||||
let mut conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(SQLiteConnectionFactory::inMemory(), &m, &mut logic)?;
|
||||
process_command_line(SQLiteConnectionFactory::in_memory(), &m, &mut logic)?;
|
||||
assert_eq!(logic.run_webui_count, 1);
|
||||
Ok(())
|
||||
}
|
||||
@@ -532,12 +532,12 @@ impl CommandLineUserLogic for ProCommandLineLogic {
|
||||
|
||||
fn run_webui(
|
||||
&mut self,
|
||||
connFact: SQLiteConnectionFactory,
|
||||
conn_fact: SQLiteConnectionFactory,
|
||||
port: u16,
|
||||
enable_template_autoreload: bool,
|
||||
) -> CustomResult<()> {
|
||||
info!("Serving web-ui on port {:?}", port);
|
||||
web_ui_main(connFact, port, enable_template_autoreload)
|
||||
web_ui_main(conn_fact, port, enable_template_autoreload)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,9 +560,9 @@ fn main() -> CustomResult<()> {
|
||||
let m = command.get_matches();
|
||||
|
||||
set_logger(&m);
|
||||
let connFactory = get_connection(&m);
|
||||
let conn_factory = get_connection(&m);
|
||||
|
||||
apply_migrations(&mut connFactory.connection()?).unwrap();
|
||||
apply_migrations(&mut conn_factory.connection()?).unwrap();
|
||||
let mut logic = ProCommandLineLogic::new();
|
||||
process_command_line(connFactory, &m, &mut logic)
|
||||
process_command_line(conn_factory, &m, &mut logic)
|
||||
}
|
||||
+1
-1
@@ -68,7 +68,7 @@ impl SQLiteConnectionFactory {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inMemory() -> SQLiteConnectionFactory {
|
||||
pub fn in_memory() -> SQLiteConnectionFactory {
|
||||
SQLiteConnectionFactory {
|
||||
creator: SQLiteConnectionCreator::Ephemeral(EphemeralSQLiteConnectionCreator {}),
|
||||
}
|
||||
|
||||
+4
-11
@@ -24,13 +24,6 @@ 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>,
|
||||
@@ -84,7 +77,7 @@ fn create_auto_reloader(enable_template_autoreload: bool) -> AutoReloader {
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn web_ui_main(
|
||||
connFact: SQLiteConnectionFactory,
|
||||
conn_fact: SQLiteConnectionFactory,
|
||||
port: u16,
|
||||
enable_template_autoreload: bool,
|
||||
) -> CustomResult<()> {
|
||||
@@ -95,12 +88,12 @@ pub async fn web_ui_main(
|
||||
|
||||
let tmpl_reloader = web::Data::new(tmpl_reloader);
|
||||
|
||||
let clonedConnFact = connFact.clone();
|
||||
let cloned_conn_fact = conn_fact.clone();
|
||||
let server = HttpServer::new(move || {
|
||||
App::new()
|
||||
.app_data(tmpl_reloader.clone())
|
||||
.app_data(web::Data::new(event_sender.clone()))
|
||||
.app_data(web::Data::new(clonedConnFact.clone()))
|
||||
.app_data(web::Data::new(cloned_conn_fact.clone()))
|
||||
.service(
|
||||
actix_files::Files::new("/static", "./resources/static/").use_last_modified(true),
|
||||
)
|
||||
@@ -120,7 +113,7 @@ pub async fn web_ui_main(
|
||||
.unwrap();
|
||||
|
||||
let t1 = server.run().fuse();
|
||||
let t2 = event_processor_loop(connFact, event_receiver).fuse();
|
||||
let t2 = event_processor_loop(conn_fact, event_receiver).fuse();
|
||||
let t3 = bob().fuse();
|
||||
pin_mut!(t1, t2, t3);
|
||||
|
||||
|
||||
+2
-2
@@ -25,9 +25,9 @@ pub async fn actions(tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Resp
|
||||
#[actix_web::get("/overview")]
|
||||
pub async fn overview(
|
||||
tmpl_env: MiniJinjaRenderer,
|
||||
connFactory: web::Data<SQLiteConnectionFactory>,
|
||||
conn_factory: web::Data<SQLiteConnectionFactory>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let conn = connFactory.readonly().unwrap(); // todo; to proper 500
|
||||
let conn = conn_factory.readonly().unwrap(); // todo; to proper 500
|
||||
let service_factory = ServiceFactory::new(&conn);
|
||||
let user_service = service_factory.get_user_service();
|
||||
let users = user_service.list_users().unwrap();
|
||||
|
||||
+2
-2
@@ -11,12 +11,12 @@ use crate::util::{CustomResult, SQLiteConnectionFactory};
|
||||
|
||||
// todo, all the "?" and handle the exceptions for real
|
||||
pub async fn event_processor_loop(
|
||||
conFact: SQLiteConnectionFactory,
|
||||
conn_fact: SQLiteConnectionFactory,
|
||||
r: async_channel::Receiver<Event>,
|
||||
) -> CustomResult<()> {
|
||||
loop {
|
||||
let res = r.recv().await;
|
||||
let mut conn = conFact.connection()?;
|
||||
let mut conn = conn_fact.connection()?;
|
||||
match res {
|
||||
Ok(event) => process_event(&mut conn, event)?,
|
||||
Err(e) => {
|
||||
|
||||
Reference in new issue
Block a user