From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager v4 5/8] ui: tasks: add helper to summarize task categories
Date: Tue, 26 Aug 2025 12:15:15 +0200 [thread overview]
Message-ID: <20250826102229.2271453-6-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250826102229.2271453-1-d.csapak@proxmox.com>
introduce a helper struct that can easily hold the info we need for
which category a workertype falls in. With methods to create from a str
(intentionally not using FromStr or From<&str> here as those should be
obvious what they do and having an explicit function is better here,
same for having to_filter and to_title, instead of display)
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v3:
* use a struct instead of free standing function that convert between
strings
ui/src/tasks.rs | 79 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/ui/src/tasks.rs b/ui/src/tasks.rs
index 1129e6a..5e4a44e 100644
--- a/ui/src/tasks.rs
+++ b/ui/src/tasks.rs
@@ -121,3 +121,82 @@ pub fn format_optional_remote_upid(upid: &str, include_remote: bool) -> String {
format_upid(upid)
}
}
+
+/// Map worker types to sensible categories (that can also be used as filter for the api)
+#[derive(Clone, PartialEq, PartialOrd, Eq, Ord)]
+/// Map worker types to sensible categories
+pub enum TaskWorkerType {
+ Migrate,
+ Qemu,
+ Lxc,
+ Ceph,
+ Ha,
+ Backup,
+ Other(String),
+ Remote(String),
+}
+
+/// Map a category from [`map_worker_type`] to a title text.
+impl TaskWorkerType {
+ /// Create new from a given worker type string, e.g. from a UPID
+ pub fn new_from_str<A: AsRef<str>>(worker_type: A) -> Self {
+ match worker_type.as_ref() {
+ task_type if task_type.contains("migrate") => TaskWorkerType::Migrate,
+ task_type if task_type.starts_with("qm") => TaskWorkerType::Qemu,
+ task_type if task_type.starts_with("vz") && task_type != "vzdump" => {
+ TaskWorkerType::Lxc
+ }
+ task_type if task_type == "vzdump" => TaskWorkerType::Backup,
+ task_type if task_type.starts_with("ceph") => TaskWorkerType::Ceph,
+ task_type if task_type.starts_with("ha") => TaskWorkerType::Ha,
+ other => TaskWorkerType::Other(other.to_string()),
+ }
+ }
+
+ /// Create title from the categories
+ pub fn to_title(&self) -> String {
+ match self {
+ TaskWorkerType::Migrate => tr!("Guest Migrations"),
+ TaskWorkerType::Qemu => tr!("Virtual Machine related Tasks"),
+ TaskWorkerType::Lxc => tr!("Container related Tasks"),
+ TaskWorkerType::Ceph => tr!("Ceph related Tasks"),
+ TaskWorkerType::Ha => tr!("HA related Tasks"),
+ TaskWorkerType::Backup => tr!("Backups and Backup Jobs"),
+ TaskWorkerType::Other(other) => other.to_string(),
+ TaskWorkerType::Remote(remote) => remote.to_string(),
+ }
+ }
+
+ /// Create filter string for the api
+ ///
+ /// Note: The result has to be filtered with this again, since more records will be returned.
+ /// E.g. using 'vz' will also return 'vzdump' tasks which are not desired.
+ pub fn to_filter<'a>(&'a self) -> &'a str {
+ match self {
+ TaskWorkerType::Migrate => "migrate",
+ TaskWorkerType::Qemu => "qm",
+ TaskWorkerType::Lxc => "vz",
+ TaskWorkerType::Ceph => "ceph",
+ TaskWorkerType::Ha => "ha",
+ TaskWorkerType::Backup => "vzdump",
+ TaskWorkerType::Other(other) => other.as_str(),
+ TaskWorkerType::Remote(remote) => remote.as_str(),
+ }
+ }
+}
+
+impl From<TaskWorkerType> for Key {
+ fn from(value: TaskWorkerType) -> Self {
+ match value {
+ TaskWorkerType::Migrate => Key::from("migrate"),
+ TaskWorkerType::Qemu => Key::from("qm"),
+ TaskWorkerType::Lxc => Key::from("vz"),
+ TaskWorkerType::Ceph => Key::from("ceph"),
+ TaskWorkerType::Ha => Key::from("ha"),
+ TaskWorkerType::Backup => Key::from("vzdump"),
+ // use `__` prefix here so that they can't clash with the statically defined ones
+ TaskWorkerType::Other(other) => Key::from(format!("__{other}")),
+ TaskWorkerType::Remote(remote) => Key::from(format!("__remote_{remote}")),
+ }
+ }
+}
--
2.47.2
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
next prev parent reply other threads:[~2025-08-26 10:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-26 10:15 [pdm-devel] [PATCH datacenter-manager v4 0/8] add task summary panels in dashboard Dominik Csapak
2025-08-26 10:15 ` [pdm-devel] [PATCH datacenter-manager v4 1/8] server: task cache: treat a limit of 0 as unbounded Dominik Csapak
2025-08-26 10:15 ` [pdm-devel] [PATCH datacenter-manager v4 2/8] server: api: remote tasks: add 'remote' filter option Dominik Csapak
2025-08-26 10:15 ` [pdm-devel] [PATCH datacenter-manager v4 3/8] server: api: add remote-tasks statistics Dominik Csapak
2025-08-26 10:15 ` [pdm-devel] [PATCH datacenter-manager v4 4/8] ui: refactor remote upid formatter Dominik Csapak
2025-08-26 10:15 ` Dominik Csapak [this message]
2025-08-26 10:15 ` [pdm-devel] [PATCH datacenter-manager v4 6/8] ui: add dialog to show filtered tasks Dominik Csapak
2025-08-26 10:15 ` [pdm-devel] [PATCH datacenter-manager v4 7/8] ui: dashboard: add task summaries Dominik Csapak
2025-08-26 10:15 ` [pdm-devel] [PATCH datacenter-manager v4 8/8] ui: dashboard: make task summary time range configurable Dominik Csapak
2025-08-26 12:41 ` [pdm-devel] [PATCH datacenter-manager v4 0/8] add task summary panels in dashboard Stefan Hanreich
2025-09-04 19:21 ` [pdm-devel] applied-series: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250826102229.2271453-6-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox