feat: event-driven parity, Windows shell detection, dirty build timestamps, and gatekeeper integration
This commit is contained in:
1 parent
64857f9d5e
commit
f4dcf3acbf
33 files changed
+3501
-143
No files matched your search
+66
-19
@@ -14,33 +14,80 @@ pub async fn wait_for_event_handler(
|
||||
) -> impl IntoResponse {
|
||||
let topic = params.get("topic").cloned();
|
||||
let session_id = params.get("session_id").cloned();
|
||||
let timeout_duration = params
|
||||
.get("timeout_ms")
|
||||
.and_then(|ms| ms.parse::<u64>().ok())
|
||||
.map(tokio::time::Duration::from_millis)
|
||||
.or_else(|| {
|
||||
params
|
||||
.get("timeout")
|
||||
.and_then(|secs| secs.parse::<u64>().ok())
|
||||
.map(tokio::time::Duration::from_secs)
|
||||
});
|
||||
|
||||
let mut rx = state.handler.state.event_bus_tx.subscribe();
|
||||
|
||||
loop {
|
||||
match rx.recv().await {
|
||||
Ok(event) => {
|
||||
let topic_matches = topic.as_ref().is_none_or(|t| t == &event.topic);
|
||||
let session_matches = session_id
|
||||
.as_ref()
|
||||
.is_none_or(|s| Some(s) == event.session_id.as_ref());
|
||||
let wait_future = async {
|
||||
loop {
|
||||
match rx.recv().await {
|
||||
Ok(event) => {
|
||||
let topic_matches = topic.as_ref().is_none_or(|t| t == &event.topic);
|
||||
let session_matches = session_id
|
||||
.as_ref()
|
||||
.is_none_or(|s| Some(s) == event.session_id.as_ref());
|
||||
|
||||
if topic_matches && session_matches {
|
||||
return axum::Json(event);
|
||||
if topic_matches && session_matches {
|
||||
return Ok(event);
|
||||
}
|
||||
}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Lagged(skipped)) => {
|
||||
tracing::warn!("Event bus receiver lagged by {} messages; continuing wait.", skipped);
|
||||
continue;
|
||||
}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Closed) => {
|
||||
return Err("Event bus closed");
|
||||
}
|
||||
}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Lagged(skipped)) => {
|
||||
tracing::warn!("Event bus receiver lagged by {} messages; continuing wait.", skipped);
|
||||
continue;
|
||||
}
|
||||
Err(tokio::sync::broadcast::error::RecvError::Closed) => {
|
||||
return axum::Json(GenericEvent {
|
||||
}
|
||||
};
|
||||
|
||||
match timeout_duration {
|
||||
Some(dur) => match tokio::time::timeout(dur, wait_future).await {
|
||||
Ok(Ok(event)) => (axum::http::StatusCode::OK, axum::Json(event)).into_response(),
|
||||
Ok(Err(err)) => (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(GenericEvent {
|
||||
topic: "error".to_string(),
|
||||
session_id: None,
|
||||
payload: serde_json::json!({"error": "Event bus closed"}),
|
||||
});
|
||||
}
|
||||
}
|
||||
payload: serde_json::json!({ "error": err }),
|
||||
}),
|
||||
)
|
||||
.into_response(),
|
||||
Err(_) => (
|
||||
axum::http::StatusCode::REQUEST_TIMEOUT,
|
||||
axum::Json(GenericEvent {
|
||||
topic: "timeout".to_string(),
|
||||
session_id: None,
|
||||
payload: serde_json::json!({
|
||||
"error": "timed out waiting for event",
|
||||
"topic": topic
|
||||
}),
|
||||
}),
|
||||
)
|
||||
.into_response(),
|
||||
},
|
||||
None => match wait_future.await {
|
||||
Ok(event) => (axum::http::StatusCode::OK, axum::Json(event)).into_response(),
|
||||
Err(err) => (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(GenericEvent {
|
||||
topic: "error".to_string(),
|
||||
session_id: None,
|
||||
payload: serde_json::json!({ "error": err }),
|
||||
}),
|
||||
)
|
||||
.into_response(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user