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 4BF061FF17C for ; Wed, 20 Aug 2025 14:42:01 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 416E2A7A2; Wed, 20 Aug 2025 14:43:47 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Wed, 20 Aug 2025 14:43:25 +0200 Message-ID: <20250820124329.220124-4-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250820124329.220124-1-l.wagner@proxmox.com> References: <20250820124329.220124-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1755693780369 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.023 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mod.rs, lib.rs] Subject: [pdm-devel] [PATCH proxmox-datacenter-manager v7 3/7] pdm-api-types: remote tasks: add new_from_str constructor for TaskStateType 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" This allows us to get rid of the `tasktype` helper in server::remote_tasks. We don't impl `From<&str>` because those should be value-preserving, lossless and obvious. Also, the function is not called from_str to avoid any confusion with FromStr. Signed-off-by: Lukas Wagner Reviewed-by: Dominik Csapak --- Notes: No changes in v6 No changes in v5 No changes in v4 Changes in v3: - move the function to TaskStateType::new_from_str instead of From<&str> lib/pdm-api-types/src/lib.rs | 15 +++++++++++++++ server/src/remote_tasks/mod.rs | 15 +-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/pdm-api-types/src/lib.rs b/lib/pdm-api-types/src/lib.rs index 38449071..9373725c 100644 --- a/lib/pdm-api-types/src/lib.rs +++ b/lib/pdm-api-types/src/lib.rs @@ -232,6 +232,21 @@ pub enum TaskStateType { Unknown, } +impl TaskStateType { + /// Construct a new instance from a `&str`. + pub fn new_from_str(status: &str) -> Self { + if status == "unknown" || status.is_empty() { + TaskStateType::Unknown + } else if status == "OK" { + TaskStateType::OK + } else if status.starts_with("WARNINGS: ") { + TaskStateType::Warning + } else { + TaskStateType::Error + } + } +} + #[api( properties: { upid: { schema: UPID::API_SCHEMA }, diff --git a/server/src/remote_tasks/mod.rs b/server/src/remote_tasks/mod.rs index cec2cc1e..8638ebd8 100644 --- a/server/src/remote_tasks/mod.rs +++ b/server/src/remote_tasks/mod.rs @@ -91,7 +91,7 @@ pub async fn get_tasks(filters: TaskFilters) -> Result, Error> } } - let state = item.status.as_ref().map(|status| tasktype(status)); + let state = item.status.as_deref().map(TaskStateType::new_from_str); match (state, &filters.statusfilter) { (Some(TaskStateType::OK), _) if filters.errors => return false, @@ -152,16 +152,3 @@ pub fn get_cache() -> Result { Ok(cache) } - -/// Parses a task status string into a TaskStateType -pub fn tasktype(status: &str) -> TaskStateType { - if status == "unknown" || status.is_empty() { - TaskStateType::Unknown - } else if status == "OK" { - TaskStateType::OK - } else if status.starts_with("WARNINGS: ") { - TaskStateType::Warning - } else { - TaskStateType::Error - } -} -- 2.47.2 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel