diff options
Diffstat (limited to 'src/routes/start.rs')
-rw-r--r-- | src/routes/start.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/routes/start.rs b/src/routes/start.rs index 271f924..401ae97 100644 --- a/src/routes/start.rs +++ b/src/routes/start.rs | |||
@@ -22,7 +22,7 @@ pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap | |||
22 | let device = sqlx::query_as!( | 22 | let device = sqlx::query_as!( |
23 | Device, | 23 | Device, |
24 | r#" | 24 | r#" |
25 | SELECT id, mac, broadcast_addr, ip | 25 | SELECT id, mac, broadcast_addr, ip, times |
26 | FROM devices | 26 | FROM devices |
27 | WHERE id = $1; | 27 | WHERE id = $1; |
28 | "#, | 28 | "#, |
@@ -40,19 +40,20 @@ pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap | |||
40 | &device.broadcast_addr.parse().map_err(WebolError::IpParse)?, | 40 | &device.broadcast_addr.parse().map_err(WebolError::IpParse)?, |
41 | create_buffer(&device.mac)? | 41 | create_buffer(&device.mac)? |
42 | )?; | 42 | )?; |
43 | 43 | let dev_id = device.id.clone(); | |
44 | let uuid = if payload.ping.is_some_and(|ping| ping) { | 44 | let uuid = if payload.ping.is_some_and(|ping| ping) { |
45 | let uuid_gen = Uuid::new_v4().to_string(); | 45 | let uuid_gen = Uuid::new_v4().to_string(); |
46 | let uuid_genc = uuid_gen.clone(); | 46 | let uuid_genc = uuid_gen.clone(); |
47 | // TODO: Check if service already runs | ||
47 | tokio::spawn(async move { | 48 | tokio::spawn(async move { |
48 | debug!("init ping service"); | 49 | debug!("init ping service"); |
49 | state.ping_map.insert(uuid_gen.clone(), PingValue { ip: device.ip.clone(), online: false }); | 50 | state.ping_map.insert(uuid_gen.clone(), PingValue { ip: device.ip.clone(), online: false }); |
50 | 51 | ||
51 | crate::services::ping::spawn(state.ping_send.clone(), device.ip, uuid_gen.clone(), &state.ping_map).await | 52 | crate::services::ping::spawn(state.ping_send.clone(), device, uuid_gen.clone(), &state.ping_map, &state.db).await |
52 | }); | 53 | }); |
53 | Some(uuid_genc) | 54 | Some(uuid_genc) |
54 | } else { None }; | 55 | } else { None }; |
55 | Ok(Json(json!(StartResponse { id: device.id, boot: true, uuid }))) | 56 | Ok(Json(json!(StartResponse { id: dev_id, boot: true, uuid }))) |
56 | } else { | 57 | } else { |
57 | Err(WebolError::Generic) | 58 | Err(WebolError::Generic) |
58 | } | 59 | } |