diff --git a/uplink/src/base/bridge/mod.rs b/uplink/src/base/bridge/mod.rs index f67ac272e..879e34b31 100644 --- a/uplink/src/base/bridge/mod.rs +++ b/uplink/src/base/bridge/mod.rs @@ -207,44 +207,7 @@ impl Bridge { select! { action = self.actions_rx.recv_async() => { let action = action?; - let action_id = action.action_id.clone(); - // Reactlabs setup processes logs generated by uplink - info!("Received action: {:?}", action); - - if let Some(current_action) = &self.current_action { - if action.name != TUNSHELL_ACTION { - warn!("Another action is currently occupying uplink; action_id = {}", current_action.id); - self.forward_action_error(action, Error::Busy).await; - continue - } - } - - // NOTE: Don't do any blocking operations here - // TODO: Remove blocking here. Audit all blocking functions here - let error = match self.try_route_action(action.clone()) { - Ok(_) => { - let response = ActionResponse::progress(&action_id, "Received", 0); - self.forward_action_response(response).await; - continue; - } - Err(e) => e, - }; - // Ignore sending failure status to backend. This makes - // backend retry action. - // - // TODO: Do we need this? Shouldn't backend have an easy way to - // retry failed actions in bulk? - if self.config.ignore_actions_if_no_clients { - error!("No clients connected, ignoring action = {:?}", action_id); - self.current_action = None; - continue; - } - - error!("Failed to route action to app. Error = {:?}", error); - self.forward_action_error(action, error).await; - - // Remove action because it couldn't be routed - self.clear_current_action() + self.handle_action(action).await; } event = self.bridge_rx.recv_async() => { let event = event?; @@ -293,6 +256,50 @@ impl Bridge { } } + async fn handle_action(&mut self, action: Action) { + let action_id = action.action_id.clone(); + // Reactlabs setup processes logs generated by uplink + info!("Received action: {:?}", action); + + if let Some(current_action) = &self.current_action { + if action.name != TUNSHELL_ACTION { + warn!( + "Another action is currently occupying uplink; action_id = {}", + current_action.id + ); + self.forward_action_error(action, Error::Busy).await; + return; + } + } + + // NOTE: Don't do any blocking operations here + // TODO: Remove blocking here. Audit all blocking functions here + let error = match self.try_route_action(action.clone()) { + Ok(_) => { + let response = ActionResponse::progress(&action_id, "Received", 0); + self.forward_action_response(response).await; + return; + } + Err(e) => e, + }; + + // Remove action because it couldn't be routed + self.clear_current_action(); + + // Ignore sending failure status to backend. This makes + // backend retry action. + // + // TODO: Do we need this? Shouldn't backend have an easy way to + // retry failed actions in bulk? + if self.config.ignore_actions_if_no_clients { + error!("No clients connected, ignoring action = {:?}", action_id); + return; + } + + error!("Failed to route action to app. Error = {:?}", error); + self.forward_action_error(action, error).await; + } + /// Save current action information in persistence fn save_current_action(&mut self) -> Result<(), Error> { let current_action = match self.current_action.take() {