From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 6/8] pdm-api-types: remote tasks: implement From<&str> for TaskStateType
Date: Fri, 14 Mar 2025 15:12:23 +0100 [thread overview]
Message-ID: <20250314141225.240768-7-l.wagner@proxmox.com> (raw)
In-Reply-To: <20250314141225.240768-1-l.wagner@proxmox.com>
This allows us to get rid of the `tasktype` helper in
server::remote_tasks.
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
---
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..209155a2 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 From<&str> for TaskStateType {
+ /// Parses a task status string into a TaskStateType
+ fn from(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 48d54694..e4304a3a 100644
--- a/server/src/remote_tasks/mod.rs
+++ b/server/src/remote_tasks/mod.rs
@@ -132,7 +132,7 @@ pub async fn get_tasks(filters: TaskFilters) -> Result<Vec<TaskListItem>, Error>
}
}
- let state = item.status.as_ref().map(|status| tasktype(status));
+ let state = item.status.as_deref().map(TaskStateType::from);
match (state, &filters.statusfilter) {
(Some(TaskStateType::OK), _) if filters.errors => return false,
@@ -471,16 +471,3 @@ fn map_pve_task(task: ListTasksResponse, remote: &str) -> Result<TaskCacheItem,
status: task.status,
})
}
-
-/// 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.39.5
_______________________________________________
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-03-14 14:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 14:12 [pdm-devel] [PATCH proxmox-datacenter-manager 0/8] remote task cache fetching task / better cache backend Lukas Wagner
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 1/8] test support: add NamedTempFile helper Lukas Wagner
2025-04-09 12:50 ` [pdm-devel] applied: " Thomas Lamprecht
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 2/8] test support: add NamedTempDir helper Lukas Wagner
2025-04-09 12:50 ` [pdm-devel] applied: " Thomas Lamprecht
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 3/8] move task_cache.rs to remote_tasks/mod.rs Lukas Wagner
2025-04-09 12:50 ` [pdm-devel] applied: " Thomas Lamprecht
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 4/8] remote tasks: implement improved cache for remote tasks Lukas Wagner
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 5/8] remote tasks: add background task for task polling, use new task cache Lukas Wagner
2025-03-20 17:39 ` Thomas Lamprecht
2025-03-21 13:33 ` Lukas Wagner
2025-03-21 13:39 ` Max Carrara
2025-04-11 8:03 ` Lukas Wagner
2025-03-14 14:12 ` Lukas Wagner [this message]
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 7/8] fake remote: add missing fields to make the debug feature compile again Lukas Wagner
2025-04-09 12:52 ` [pdm-devel] applied: " Thomas Lamprecht
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 8/8] fake remote: generate fake task data Lukas Wagner
2025-04-09 12:52 ` [pdm-devel] applied: " Thomas Lamprecht
2025-04-11 11:02 ` [pdm-devel] superseded: [PATCH proxmox-datacenter-manager 0/8] remote task cache fetching task / better cache backend Lukas Wagner
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=20250314141225.240768-7-l.wagner@proxmox.com \
--to=l.wagner@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal