[pdm-devel] [PATCH proxmox-datacenter-manager 09/15] remote tasks: return tasks in stable order
Lukas Wagner
l.wagner at proxmox.com
Tue Jan 28 13:25:14 CET 2025
Since the tasks are retrieved from the cache by key and this key comes
from iterating a hashmap, the order of the tasks with the same start
time was unstable. Since we have to sort anyway, we can fix this by
simply using a tasks UPID as a secondary sorting criterium. The
UPID starts with the remote's name, so this boils down to using the
remote name as a secondary criterium.
Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
server/src/remote_tasks/mod.rs | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/server/src/remote_tasks/mod.rs b/server/src/remote_tasks/mod.rs
index 16c46a5..3da6f25 100644
--- a/server/src/remote_tasks/mod.rs
+++ b/server/src/remote_tasks/mod.rs
@@ -1,4 +1,5 @@
use std::{
+ cmp::Ordering,
collections::HashSet,
path::Path,
sync::{LazyLock, RwLock},
@@ -73,7 +74,15 @@ pub async fn get_tasks(filters: TaskFilters) -> Result<Vec<TaskListItem>, Error>
}
let mut returned_tasks = add_running_tasks(all_tasks)?;
- returned_tasks.sort_by(|a, b| b.starttime.cmp(&a.starttime));
+
+ // Sort merged tasks by starttime, falling back to UPID if the starttime is equal.
+ // This UPID starts with the remote name, so this equates to using the remote name
+ // as a secondary sorting criterium.
+ returned_tasks.sort_by(|a, b| match b.starttime.cmp(&a.starttime) {
+ Ordering::Equal => a.upid.cmp(&b.upid),
+ ord => ord,
+ });
+
let returned_tasks = returned_tasks
.into_iter()
.filter(|item| {
--
2.39.5
More information about the pdm-devel
mailing list