Skip to content

Commit

Permalink
Upgrade to axum 0.8
Browse files Browse the repository at this point in the history
shepmaster committed Jan 14, 2025
1 parent 119ceab commit 9becf29
Showing 4 changed files with 23 additions and 57 deletions.
60 changes: 15 additions & 45 deletions ui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions ui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -10,9 +10,8 @@ fork-bomb-prevention = []

[dependencies]
asm-cleanup = { path = "../compiler/base/asm-cleanup" }
async-trait = "0.1.52"
axum = { version = "0.7", features = ["ws"] }
axum-extra = { version = "0.9.0", features = ["typed-header"] }
axum = { version = "0.8", features = ["ws"] }
axum-extra = { version = "0.10", features = ["typed-header"] }
dotenv = "0.15.0"
futures = "0.3.21"
octocrab = "0.42"
5 changes: 1 addition & 4 deletions ui/src/server_axum.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ use crate::{
request_database::Handle,
Config, GhToken, MetricsToken, WebSocketConfig,
};
use async_trait::async_trait;
use axum::{
body::Body,
extract::{self, ws::WebSocketUpgrade, Extension, Path},
@@ -100,7 +99,7 @@ pub(crate) async fn serve(config: Config) {
.route("/meta/versions", get(meta_versions))
.route("/meta/gist", post(meta_gist_create))
.route("/meta/gist/", post(meta_gist_create)) // compatibility with lax frontend code
.route("/meta/gist/:id", get(meta_gist_get))
.route("/meta/gist/{id}", get(meta_gist_get))
.route("/metrics", get(metrics))
.route("/websocket", get(websocket))
.route("/nowebsocket", post(nowebsocket))
@@ -712,7 +711,6 @@ enum CacheVersionsError {
Shutdown { source: coordinator::Error },
}

#[async_trait]
impl<S> extract::FromRequestParts<S> for MetricsAuthorization
where
S: Send + Sync,
@@ -756,7 +754,6 @@ impl IntoResponse for Error {
/// error and format it using our expected JSON error object.
struct Json<T>(T);

#[async_trait]
impl<T, S> extract::FromRequest<S> for Json<T>
where
T: serde::de::DeserializeOwned,
10 changes: 5 additions & 5 deletions ui/src/server_axum/websocket.rs
Original file line number Diff line number Diff line change
@@ -380,7 +380,7 @@ async fn handle_core(
// browser disconnected
break;
}
Some(Ok(Message::Text(txt))) => handle_msg(txt, &tx, &mut manager, &mut active_executions, &db).await,
Some(Ok(Message::Text(txt))) => handle_msg(&txt, &tx, &mut manager, &mut active_executions, &db).await,
Some(Ok(_)) => {
// unknown message type
continue;
@@ -507,7 +507,7 @@ fn response_to_message(response: MessageResponse) -> Message {
const LAST_CHANCE_ERROR: &str =
r#"{ "type": "WEBSOCKET_ERROR", "error": "Unable to serialize JSON" }"#;
let resp = serde_json::to_string(&response).unwrap_or_else(|_| LAST_CHANCE_ERROR.into());
Message::Text(resp)
Message::Text(resp.into())
}

async fn handle_idle(manager: &mut CoordinatorManager, tx: &ResponseTx) -> ControlFlow<()> {
@@ -528,22 +528,22 @@ async fn handle_idle(manager: &mut CoordinatorManager, tx: &ResponseTx) -> Contr
type ActiveExecutionInfo = (CancellationToken, Option<mpsc::Sender<String>>);

async fn handle_msg(
txt: String,
txt: &str,
tx: &ResponseTx,
manager: &mut CoordinatorManager,
active_executions: &mut BTreeMap<i64, ActiveExecutionInfo>,
db: &Handle,
) {
use WSMessageRequest::*;

let msg = serde_json::from_str(&txt).context(DeserializationSnafu);
let msg = serde_json::from_str(txt).context(DeserializationSnafu);

match msg {
Ok(ExecuteRequest { payload, meta }) => {
let token = CancellationToken::new();
let (execution_tx, execution_rx) = mpsc::channel(8);

let guard = db.clone().start_with_guard("ws.Execute", &txt).await;
let guard = db.clone().start_with_guard("ws.Execute", txt).await;

active_executions.insert(meta.sequence_number, (token.clone(), Some(execution_tx)));

0 comments on commit 9becf29

Please sign in to comment.