summaryrefslogtreecommitdiff
path: root/makima/src/server/handlers/mesh_supervisor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/server/handlers/mesh_supervisor.rs')
-rw-r--r--makima/src/server/handlers/mesh_supervisor.rs59
1 files changed, 49 insertions, 10 deletions
diff --git a/makima/src/server/handlers/mesh_supervisor.rs b/makima/src/server/handlers/mesh_supervisor.rs
index 1b476ef..d1a1a99 100644
--- a/makima/src/server/handlers/mesh_supervisor.rs
+++ b/makima/src/server/handlers/mesh_supervisor.rs
@@ -1349,6 +1349,9 @@ pub async fn merge_task(
).into_response();
};
+ // Subscribe to merge results BEFORE sending the command
+ let mut rx = state.merge_results.subscribe();
+
// Send MergeTaskToTarget command to daemon
let cmd = DaemonCommand::MergeTaskToTarget {
task_id,
@@ -1364,16 +1367,52 @@ pub async fn merge_task(
).into_response();
}
- (
- StatusCode::OK,
- Json(MergeTaskResponse {
- task_id,
- success: true,
- message: "Merge command sent".to_string(),
- commit_sha: None,
- conflicts: None,
- }),
- ).into_response()
+ // Wait for the merge result with a timeout (60 seconds should be plenty for a merge)
+ let timeout = tokio::time::Duration::from_secs(60);
+ let result = tokio::time::timeout(timeout, async {
+ loop {
+ match rx.recv().await {
+ Ok(notification) => {
+ if notification.task_id == task_id {
+ return Some(notification);
+ }
+ // Not our task, keep waiting
+ }
+ Err(_) => {
+ // Channel closed or lagged
+ return None;
+ }
+ }
+ }
+ }).await;
+
+ match result {
+ Ok(Some(notification)) => {
+ (
+ StatusCode::OK,
+ Json(MergeTaskResponse {
+ task_id,
+ success: notification.success,
+ message: notification.message,
+ commit_sha: notification.commit_sha,
+ conflicts: notification.conflicts,
+ }),
+ ).into_response()
+ }
+ Ok(None) | Err(_) => {
+ // Timeout or channel error - return error status
+ (
+ StatusCode::GATEWAY_TIMEOUT,
+ Json(MergeTaskResponse {
+ task_id,
+ success: false,
+ message: "Merge operation timed out waiting for daemon response".to_string(),
+ commit_sha: None,
+ conflicts: None,
+ }),
+ ).into_response()
+ }
+ }
}
/// Create a pull request for a task's changes.