aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorfx <[email protected]>2023-10-24 01:15:22 +0200
committerfx <[email protected]>2023-10-24 01:15:22 +0200
commitdcfb83fb2069bfcf4642b03453253e35479bf3da (patch)
treeccdacf40274227e86a8294558347aeea43b1724f /src/main.rs
parentd9d7b125e4fcaa3aedd7b57a69e6880e012ccf33 (diff)
downloadwebol-dcfb83fb2069bfcf4642b03453253e35479bf3da.tar
webol-dcfb83fb2069bfcf4642b03453253e35479bf3da.tar.gz
webol-dcfb83fb2069bfcf4642b03453253e35479bf3da.zip
first ping impl baseline, doesnt work
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index ce12cf6..9c31ec8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,12 +4,14 @@ use axum::{Router, routing::post};
4use axum::routing::{get, put}; 4use axum::routing::{get, put};
5use sqlx::PgPool; 5use sqlx::PgPool;
6use time::util::local_offset; 6use time::util::local_offset;
7use tokio::sync::mpsc::{self, Sender};
7use tracing::{info, level_filters::LevelFilter}; 8use tracing::{info, level_filters::LevelFilter};
8use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; 9use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*};
9use crate::config::SETTINGS; 10use crate::config::SETTINGS;
10use crate::db::init_db_pool; 11use crate::db::init_db_pool;
11use crate::routes::device::{get_device, post_device, put_device}; 12use crate::routes::device::{get_device, post_device, put_device};
12use crate::routes::start::start; 13use crate::routes::start::start;
14use crate::services::ping::ws_ping;
13 15
14mod auth; 16mod auth;
15mod config; 17mod config;
@@ -17,6 +19,7 @@ mod routes;
17mod wol; 19mod wol;
18mod db; 20mod db;
19mod error; 21mod error;
22mod services;
20 23
21#[tokio::main] 24#[tokio::main]
22async fn main() { 25async fn main() {
@@ -43,13 +46,23 @@ async fn main() {
43 let db = init_db_pool().await; 46 let db = init_db_pool().await;
44 sqlx::migrate!().run(&db).await.unwrap(); 47 sqlx::migrate!().run(&db).await.unwrap();
45 48
46 let shared_state = Arc::new(AppState { db }); 49 let (tx, mut rx) = mpsc::channel(32);
50
51 // FIXME: once_cell? or just static mutable
52 tokio::spawn( async move {
53 while let Some(message) = rx.recv().await {
54 println!("GOT = {}", message);
55 }
56 });
57
58 let shared_state = Arc::new(AppState { db, ping_send: tx });
47 59
48 let app = Router::new() 60 let app = Router::new()
49 .route("/start", post(start)) 61 .route("/start", post(start))
50 .route("/device", get(get_device)) 62 .route("/device", get(get_device))
51 .route("/device", put(put_device)) 63 .route("/device", put(put_device))
52 .route("/device", post(post_device)) 64 .route("/device", post(post_device))
65 .route("/status", get(ws_ping))
53 .with_state(shared_state); 66 .with_state(shared_state);
54 67
55 let addr = SETTINGS.get_string("serveraddr").unwrap_or("0.0.0.0:7229".to_string()); 68 let addr = SETTINGS.get_string("serveraddr").unwrap_or("0.0.0.0:7229".to_string());
@@ -61,5 +74,7 @@ async fn main() {
61} 74}
62 75
63pub struct AppState { 76pub struct AppState {
64 db: PgPool 77 db: PgPool,
78 ping_send: Sender<String>,
79 // ping_receive: Receiver<String>
65} 80}