public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: Re: [pdm-devel] [PATCH proxmox-datacenter-manager v5 4/6] pdm-api-types: remote tasks: add new_from_str constructor for TaskStateType
Date: Thu, 15 May 2025 08:56:26 +0200	[thread overview]
Message-ID: <07aabab0-33c8-4e37-bf0c-3943ace34920@proxmox.com> (raw)
In-Reply-To: <20250512114144.118545-5-l.wagner@proxmox.com>

aside that I'm a bit unsure about the name (though I don't have a better suggesstion), consider this

Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>

On 5/12/25 13:41, Lukas Wagner wrote:
> 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 <l.wagner@proxmox.com>
> ---
> 
> Notes:
>      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 b0fc052f..f4b92809 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<Vec<TaskListItem>, 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,
> @@ -148,16 +148,3 @@ pub fn get_cache() -> Result<TaskCache, Error> {
>   
>       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
> -    }
> -}



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel


  reply	other threads:[~2025-05-15  6:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-12 11:41 [pdm-devel] [PATCH proxmox-datacenter-manager v5 0/6] remote task cache fetching task / better cache backend Lukas Wagner
2025-05-12 11:41 ` [pdm-devel] [PATCH proxmox-datacenter-manager v5 1/6] remote tasks: implement improved cache for remote tasks Lukas Wagner
2025-05-14 14:08   ` Dominik Csapak
2025-05-12 11:41 ` [pdm-devel] [PATCH proxmox-datacenter-manager v5 2/6] remote tasks: add background task for task polling, use new task cache Lukas Wagner
2025-05-14 15:27   ` Dominik Csapak
2025-05-12 11:41 ` [pdm-devel] [PATCH proxmox-datacenter-manager v5 3/6] remote tasks: improve locking for task archive iterator Lukas Wagner
2025-05-12 11:41 ` [pdm-devel] [PATCH proxmox-datacenter-manager v5 4/6] pdm-api-types: remote tasks: add new_from_str constructor for TaskStateType Lukas Wagner
2025-05-15  6:56   ` Dominik Csapak [this message]
2025-05-12 11:41 ` [pdm-devel] [PATCH proxmox-datacenter-manager v5 5/6] fake remote: make the fake_remote feature compile again Lukas Wagner
2025-05-15  6:55   ` Dominik Csapak
2025-05-12 11:41 ` [pdm-devel] [PATCH proxmox-datacenter-manager v5 6/6] fake remote: clippy fixes Lukas Wagner
2025-05-15  7:05   ` Dominik Csapak

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=07aabab0-33c8-4e37-bf0c-3943ace34920@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal