From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 0D2091FF16B for ; Tue, 26 Aug 2025 12:22:58 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6971C2F1BC; Tue, 26 Aug 2025 12:23:03 +0200 (CEST) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Tue, 26 Aug 2025 12:15:15 +0200 Message-ID: <20250826102229.2271453-6-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250826102229.2271453-1-d.csapak@proxmox.com> References: <20250826102229.2271453-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.022 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH datacenter-manager v4 5/8] ui: tasks: add helper to summarize task categories X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" 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 --- 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>(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 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