This commit is contained in:
2026-05-22 08:40:04 +02:00
parent 749638b75c
commit 777fcf168e
13 changed files with 74 additions and 56 deletions
-3
View File
@@ -33,7 +33,6 @@ pub async fn execute_for_user(
config: &Config,
) -> Result<ExecResult, (Status, String)> {
let ExecuteRequest { device_id, command } = request;
validate_execute_request(&device_id, &command, config)?;
execute(registry, user_id, &device_id, command, config)
@@ -69,14 +68,12 @@ async fn execute(
config: &Config,
) -> Result<ExecResult, String> {
let key = (user_id.to_owned(), device_id.to_owned());
let (sender, in_flight_counter) = registry
.get(&key)
.map(|entry| (entry.sender.clone(), Arc::clone(&entry.in_flight)))
.ok_or_else(|| "Device not connected".to_string())?;
claim_execution_slot(&in_flight_counter, config.max_concurrent_executions)?;
let result = send_and_await(sender, command, config).await;
in_flight_counter.fetch_sub(1, Ordering::SeqCst);
-3
View File
@@ -1,3 +0,0 @@
pub mod execute;
pub mod protocol;
pub mod socket;
+6 -4
View File
@@ -42,10 +42,12 @@ pub async fn run_loop(
break;
}
}
message = socket.next() => match handle_socket_message(socket, message, &pending).await {
SocketAction::Break => break,
SocketAction::ClearPongDeadline => awaiting_pong = false,
SocketAction::Continue => {}
message = socket.next() => {
match handle_socket_message(socket, message, &pending).await {
SocketAction::Break => break,
SocketAction::ClearPongDeadline => awaiting_pong = false,
SocketAction::Continue => {}
}
}
}
}
+5 -4
View File
@@ -15,10 +15,11 @@ pub fn connect<'r>(
device_id: MaybeDeviceId,
state: &'r State<AppState>,
) -> Channel<'r> {
let database = state.database.clone();
let registry = state.registry.clone();
let device_counts = state.device_counts.clone();
let config = state.config.clone();
let app_state = state.inner();
let database = app_state.database.clone();
let registry = app_state.registry.clone();
let device_counts = app_state.device_counts.clone();
let config = app_state.config.clone();
ws.channel(move |socket| {
Box::pin(connection::handle(