public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Lukas Wagner <l.wagner@proxmox.com>
Cc: pdm-devel@lists.proxmox.com
Subject: Re: [pdm-devel] [PATCH proxmox-datacenter-manager v2 3/4] pdm-api-types: remote tasks: implement From<&str> for TaskStateType
Date: Wed, 16 Apr 2025 16:28:59 +0200	[thread overview]
Message-ID: <qflotxmcedslsx7jrq42xf27yo3lsbzrhfizmabylhxjkgoell@7oyvqxexepay> (raw)
In-Reply-To: <20250411110117.199543-4-l.wagner@proxmox.com>

On Fri, Apr 11, 2025 at 01:01:16PM +0200, Lukas Wagner wrote:
> 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 {

IMO the From trait is not the right trait for this.

I'd rather just have this as a `from_str` method.
`From` should at least try to be lossless, value-preserving and obvious
(according to its documentation ;-) ), while this implementation fits
none of these ;-)

> +    /// 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 126c9ad3..384dd914 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::from);
>  
>                  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
> -    }
> -}
> -- 
> 2.39.5


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


  reply	other threads:[~2025-04-16 14:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-11 11:01 [pdm-devel] [PATCH proxmox-datacenter-manager v2 0/4] remote task cache fetching task / better cache backend Lukas Wagner
2025-04-11 11:01 ` [pdm-devel] [PATCH proxmox-datacenter-manager v2 1/4] remote tasks: implement improved cache for remote tasks Lukas Wagner
2025-04-16 13:15   ` Wolfgang Bumiller
2025-04-11 11:01 ` [pdm-devel] [PATCH proxmox-datacenter-manager v2 2/4] remote tasks: add background task for task polling, use new task cache Lukas Wagner
2025-04-11 11:01 ` [pdm-devel] [PATCH proxmox-datacenter-manager v2 3/4] pdm-api-types: remote tasks: implement From<&str> for TaskStateType Lukas Wagner
2025-04-16 14:28   ` Wolfgang Bumiller [this message]
2025-04-11 11:01 ` [pdm-devel] [PATCH proxmox-datacenter-manager v2 4/4] fake remote: make the fake_remote feature compile again Lukas Wagner
2025-04-17 13:25 ` [pdm-devel] superseded: [PATCH proxmox-datacenter-manager v2 0/4] 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=qflotxmcedslsx7jrq42xf27yo3lsbzrhfizmabylhxjkgoell@7oyvqxexepay \
    --to=w.bumiller@proxmox.com \
    --cc=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 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