Apply small fixes and prepare emgauwa-controller
This commit is contained in:
		
							parent
							
								
									bacea1e3e9
								
							
						
					
					
						commit
						d5583e86bc
					
				
					 9 changed files with 150 additions and 6 deletions
				
			
		
							
								
								
									
										64
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										64
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							| 
						 | 
					@ -768,6 +768,12 @@ dependencies = [
 | 
				
			||||||
 "typenum",
 | 
					 "typenum",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "data-encoding"
 | 
				
			||||||
 | 
					version = "2.5.0"
 | 
				
			||||||
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
 | 
					checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "der"
 | 
					name = "der"
 | 
				
			||||||
version = "0.7.8"
 | 
					version = "0.7.8"
 | 
				
			||||||
| 
						 | 
					@ -834,9 +840,26 @@ dependencies = [
 | 
				
			||||||
 "serde",
 | 
					 "serde",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "emgauwa-controller"
 | 
				
			||||||
 | 
					version = "0.5.0"
 | 
				
			||||||
 | 
					dependencies = [
 | 
				
			||||||
 | 
					 "chrono",
 | 
				
			||||||
 | 
					 "config",
 | 
				
			||||||
 | 
					 "emgauwa-lib",
 | 
				
			||||||
 | 
					 "futures",
 | 
				
			||||||
 | 
					 "log",
 | 
				
			||||||
 | 
					 "serde",
 | 
				
			||||||
 | 
					 "serde_derive",
 | 
				
			||||||
 | 
					 "serde_json",
 | 
				
			||||||
 | 
					 "simple_logger",
 | 
				
			||||||
 | 
					 "tokio-tungstenite",
 | 
				
			||||||
 | 
					 "uuid",
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "emgauwa-core"
 | 
					name = "emgauwa-core"
 | 
				
			||||||
version = "0.1.0"
 | 
					version = "0.5.0"
 | 
				
			||||||
dependencies = [
 | 
					dependencies = [
 | 
				
			||||||
 "actix",
 | 
					 "actix",
 | 
				
			||||||
 "actix-web",
 | 
					 "actix-web",
 | 
				
			||||||
| 
						 | 
					@ -855,7 +878,7 @@ dependencies = [
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "emgauwa-lib"
 | 
					name = "emgauwa-lib"
 | 
				
			||||||
version = "0.1.0"
 | 
					version = "0.5.0"
 | 
				
			||||||
dependencies = [
 | 
					dependencies = [
 | 
				
			||||||
 "actix",
 | 
					 "actix",
 | 
				
			||||||
 "actix-web",
 | 
					 "actix-web",
 | 
				
			||||||
| 
						 | 
					@ -2514,6 +2537,18 @@ dependencies = [
 | 
				
			||||||
 "windows-sys 0.48.0",
 | 
					 "windows-sys 0.48.0",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "tokio-tungstenite"
 | 
				
			||||||
 | 
					version = "0.20.1"
 | 
				
			||||||
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
 | 
					checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c"
 | 
				
			||||||
 | 
					dependencies = [
 | 
				
			||||||
 | 
					 "futures-util",
 | 
				
			||||||
 | 
					 "log",
 | 
				
			||||||
 | 
					 "tokio",
 | 
				
			||||||
 | 
					 "tungstenite",
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "tokio-util"
 | 
					name = "tokio-util"
 | 
				
			||||||
version = "0.7.10"
 | 
					version = "0.7.10"
 | 
				
			||||||
| 
						 | 
					@ -2569,6 +2604,25 @@ dependencies = [
 | 
				
			||||||
 "once_cell",
 | 
					 "once_cell",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "tungstenite"
 | 
				
			||||||
 | 
					version = "0.20.1"
 | 
				
			||||||
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
 | 
					checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9"
 | 
				
			||||||
 | 
					dependencies = [
 | 
				
			||||||
 | 
					 "byteorder",
 | 
				
			||||||
 | 
					 "bytes",
 | 
				
			||||||
 | 
					 "data-encoding",
 | 
				
			||||||
 | 
					 "http",
 | 
				
			||||||
 | 
					 "httparse",
 | 
				
			||||||
 | 
					 "log",
 | 
				
			||||||
 | 
					 "rand",
 | 
				
			||||||
 | 
					 "sha1",
 | 
				
			||||||
 | 
					 "thiserror",
 | 
				
			||||||
 | 
					 "url",
 | 
				
			||||||
 | 
					 "utf-8",
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "typenum"
 | 
					name = "typenum"
 | 
				
			||||||
version = "1.17.0"
 | 
					version = "1.17.0"
 | 
				
			||||||
| 
						 | 
					@ -2625,6 +2679,12 @@ dependencies = [
 | 
				
			||||||
 "percent-encoding",
 | 
					 "percent-encoding",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "utf-8"
 | 
				
			||||||
 | 
					version = "0.7.6"
 | 
				
			||||||
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
 | 
					checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "uuid"
 | 
					name = "uuid"
 | 
				
			||||||
version = "1.6.1"
 | 
					version = "1.6.1"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,5 +2,6 @@
 | 
				
			||||||
resolver = "2"
 | 
					resolver = "2"
 | 
				
			||||||
members = [
 | 
					members = [
 | 
				
			||||||
    "emgauwa-core",
 | 
					    "emgauwa-core",
 | 
				
			||||||
 | 
					    "emgauwa-controller",
 | 
				
			||||||
    "emgauwa-lib",
 | 
					    "emgauwa-lib",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										24
									
								
								emgauwa-controller/Cargo.toml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								emgauwa-controller/Cargo.toml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,24 @@
 | 
				
			||||||
 | 
					[package]
 | 
				
			||||||
 | 
					name = "emgauwa-controller"
 | 
				
			||||||
 | 
					version = "0.5.0"
 | 
				
			||||||
 | 
					edition = "2021"
 | 
				
			||||||
 | 
					authors = ["Tobias Reisinger <tobias@msrg.cc>"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[dependencies]
 | 
				
			||||||
 | 
					emgauwa-lib = { path = "../emgauwa-lib" }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					config = "0.13"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tokio-tungstenite = "0.20"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					simple_logger = "4.2"
 | 
				
			||||||
 | 
					log = "0.4"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chrono = { version = "0.4", features = ["serde"] }
 | 
				
			||||||
 | 
					uuid = { version = "1.5", features = ["serde", "v4"] }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					serde = "1.0"
 | 
				
			||||||
 | 
					serde_json = "1.0"
 | 
				
			||||||
 | 
					serde_derive = "1.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					futures = "0.3.29"
 | 
				
			||||||
							
								
								
									
										5
									
								
								emgauwa-controller/src/main.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								emgauwa-controller/src/main.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,5 @@
 | 
				
			||||||
 | 
					mod settings;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn main() {
 | 
				
			||||||
 | 
						let _settings = settings::init();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										54
									
								
								emgauwa-controller/src/settings.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								emgauwa-controller/src/settings.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,54 @@
 | 
				
			||||||
 | 
					use config::Config;
 | 
				
			||||||
 | 
					use serde_derive::Deserialize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Clone, Debug, Deserialize)]
 | 
				
			||||||
 | 
					#[serde(default)]
 | 
				
			||||||
 | 
					#[allow(unused)]
 | 
				
			||||||
 | 
					pub struct Logging {
 | 
				
			||||||
 | 
						pub level: String,
 | 
				
			||||||
 | 
						pub file: String,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Clone, Debug, Deserialize)]
 | 
				
			||||||
 | 
					#[serde(default)]
 | 
				
			||||||
 | 
					#[allow(unused)]
 | 
				
			||||||
 | 
					pub struct Settings {
 | 
				
			||||||
 | 
						pub database: String,
 | 
				
			||||||
 | 
						pub port: u16,
 | 
				
			||||||
 | 
						pub host: String,
 | 
				
			||||||
 | 
						pub logging: Logging,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Default for Settings {
 | 
				
			||||||
 | 
						fn default() -> Self {
 | 
				
			||||||
 | 
							Settings {
 | 
				
			||||||
 | 
								database: String::from("sqlite://emgauwa-controller.sqlite"),
 | 
				
			||||||
 | 
								port: 5000,
 | 
				
			||||||
 | 
								host: String::from("127.0.0.1"),
 | 
				
			||||||
 | 
								logging: Logging::default(),
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Default for Logging {
 | 
				
			||||||
 | 
						fn default() -> Self {
 | 
				
			||||||
 | 
							Logging {
 | 
				
			||||||
 | 
								level: String::from("info"),
 | 
				
			||||||
 | 
								file: String::from("stdout"),
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn init() -> Settings {
 | 
				
			||||||
 | 
						Config::builder()
 | 
				
			||||||
 | 
							.add_source(config::File::with_name("emgauwa-controller"))
 | 
				
			||||||
 | 
							.add_source(
 | 
				
			||||||
 | 
								config::Environment::with_prefix("EMGAUWA_CONTROLLER")
 | 
				
			||||||
 | 
									.prefix_separator("_")
 | 
				
			||||||
 | 
									.separator("__"),
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
							.build()
 | 
				
			||||||
 | 
							.unwrap()
 | 
				
			||||||
 | 
							.try_deserialize::<Settings>()
 | 
				
			||||||
 | 
							.unwrap_or_else(|_| panic!("Error reading settings."))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
[package]
 | 
					[package]
 | 
				
			||||||
name = "emgauwa-core"
 | 
					name = "emgauwa-core"
 | 
				
			||||||
version = "0.1.0"
 | 
					version = "0.5.0"
 | 
				
			||||||
edition = "2021"
 | 
					edition = "2021"
 | 
				
			||||||
authors = ["Tobias Reisinger <tobias@msrg.cc>"]
 | 
					authors = ["Tobias Reisinger <tobias@msrg.cc>"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,7 +43,7 @@ pub fn init() -> Settings {
 | 
				
			||||||
	Config::builder()
 | 
						Config::builder()
 | 
				
			||||||
		.add_source(config::File::with_name("emgauwa-core"))
 | 
							.add_source(config::File::with_name("emgauwa-core"))
 | 
				
			||||||
		.add_source(
 | 
							.add_source(
 | 
				
			||||||
			config::Environment::with_prefix("EMGAUWA")
 | 
								config::Environment::with_prefix("EMGAUWA_CORE")
 | 
				
			||||||
				.prefix_separator("_")
 | 
									.prefix_separator("_")
 | 
				
			||||||
				.separator("__"),
 | 
									.separator("__"),
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,10 @@
 | 
				
			||||||
[package]
 | 
					[package]
 | 
				
			||||||
name = "emgauwa-lib"
 | 
					name = "emgauwa-lib"
 | 
				
			||||||
version = "0.1.0"
 | 
					version = "0.5.0"
 | 
				
			||||||
edition = "2021"
 | 
					edition = "2021"
 | 
				
			||||||
authors = ["Tobias Reisinger <tobias@msrg.cc>"]
 | 
					authors = ["Tobias Reisinger <tobias@msrg.cc>"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[dependencies]
 | 
					[dependencies]
 | 
				
			||||||
actix = "0.13"
 | 
					actix = "0.13"
 | 
				
			||||||
actix-web = "4.4"
 | 
					actix-web = "4.4"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,6 @@ async fn get_schedules(pool: &mut Pool<Sqlite>) -> Result<Vec<Schedule>, ApiErro
 | 
				
			||||||
	Ok(Schedule::get_all(&mut pool_conn).await?)
 | 
						Ok(Schedule::get_all(&mut pool_conn).await?)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Handler for ws::Message message
 | 
					 | 
				
			||||||
impl StreamHandler<Result<Message, ProtocolError>> for ControllerWs {
 | 
					impl StreamHandler<Result<Message, ProtocolError>> for ControllerWs {
 | 
				
			||||||
	fn handle(&mut self, msg: Result<Message, ProtocolError>, ctx: &mut Self::Context) {
 | 
						fn handle(&mut self, msg: Result<Message, ProtocolError>, ctx: &mut Self::Context) {
 | 
				
			||||||
		let schedules = futures::executor::block_on(get_schedules(&mut self.pool)).unwrap();
 | 
							let schedules = futures::executor::block_on(get_schedules(&mut self.pool)).unwrap();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue