feat(profile-switch): track cleanup and coordinate pipeline

- Add explicit cleanup tracking in the driver (`cleanup_profiles` map + `CleanupDone` messages) to know when background post-switch work is still running before starting a new workflow. (driver.rs:29-50)
- Update `handle_enqueue` to detect “cleanup in progress”: same-profile retries are short-circuited; other requests collapse the pending queue, cancelling old tokens so only the latest intent survives. (driver.rs:176-247)
- Rework scheduling helpers: `start_next_job` refuses to start while cleanup is outstanding; discarded requests release cancellation tokens; cleanup completion explicitly restarts the pipeline. (driver.rs:258-442)
This commit is contained in:
Slinetrac
2025-10-27 13:41:23 +08:00
parent f88e848452
commit f1bc704e16
2 changed files with 132 additions and 43 deletions
+13 -27
View File
@@ -33,9 +33,8 @@ pub(super) async fn run_switch_job(
"Switch task {} cancelled before validation",
request.task_id()
);
handle::Handle::notify_profile_switch_finished(
schedule_post_switch_failure(
request.profile_id().clone(),
false,
request.notify(),
request.task_id(),
);
@@ -56,7 +55,7 @@ pub(super) async fn run_switch_job(
err
);
handle::Handle::notice_message("config_validate::error", err.clone());
handle::Handle::notify_profile_switch_finished(profile_id.clone(), false, notify, task_id);
schedule_post_switch_failure(profile_id.clone(), notify, task_id);
return Ok(false);
}
@@ -102,12 +101,7 @@ pub(super) async fn run_switch_job(
"config_validate::error",
format!("profile switch timed out: {}", profile_id),
);
handle::Handle::notify_profile_switch_finished(
profile_id.clone(),
false,
notify,
task_id,
);
schedule_post_switch_failure(profile_id.clone(), notify, task_id);
Ok(false)
}
Ok(Err(panic_payload)) => {
@@ -124,12 +118,7 @@ pub(super) async fn run_switch_job(
"config_validate::panic",
format!("profile switch panic: {}", profile_id),
);
handle::Handle::notify_profile_switch_finished(
profile_id.clone(),
false,
notify,
task_id,
);
schedule_post_switch_failure(profile_id.clone(), notify, task_id);
Err(SwitchPanicInfo::workflow_root(panic_message))
}
Ok(Ok(machine_result)) => match machine_result {
@@ -147,12 +136,7 @@ pub(super) async fn run_switch_job(
err
);
handle::Handle::notice_message("config_validate::error", err.clone());
handle::Handle::notify_profile_switch_finished(
profile_id.clone(),
false,
notify,
task_id,
);
schedule_post_switch_failure(profile_id.clone(), notify, task_id);
Ok(false)
}
},
@@ -170,12 +154,7 @@ pub(super) async fn run_switch_job(
"config_validate::panic",
format!("profile switch panic: {}", profile_id),
);
handle::Handle::notify_profile_switch_finished(
profile_id.clone(),
false,
notify,
task_id,
);
schedule_post_switch_failure(profile_id.clone(), notify, task_id);
Err(panic_info)
}
},
@@ -411,6 +390,13 @@ fn schedule_post_switch_success(
});
}
fn schedule_post_switch_failure(profile_id: SmartString, notify: bool, task_id: u64) {
AsyncHandler::spawn(move || async move {
handle::Handle::notify_profile_switch_finished(profile_id.clone(), false, notify, task_id);
schedule_close_connections(profile_id);
});
}
pub(super) fn describe_panic_payload(payload: &(dyn Any + Send)) -> String {
if let Some(message) = payload.downcast_ref::<&str>() {
(*message).to_string()