Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define a procedural macro for implementing administration functions easily #3365

Closed
killme2008 opened this issue Feb 22, 2024 · 0 comments
Closed
Labels
Difficulty: Mid A mid-level task
Milestone

Comments

@killme2008
Copy link
Contributor

What type of enhancement is this?

Tech debt reduction

What does the enhancement do?

Let's define a procedural macro to make implementing administration functions easier, for example, we can implement the procedure_state as below:

#[admin_fn(name = "procedure_state", return = "StringVector")]
async fn procedure_state(procedure_service_handler: &ProcedureServiceHandlerRef, pid: &str) -> Result<String > {
    let ProcedureStateResponse { status, error, .. } =                    
        procedure_service_handler.query_procedure_state(pid).await?;
    let status = ProcedureStatus::try_from(status)
        .map(|v| v.as_str_name())
        .unwrap_or("Unknown");

    let state = ProcedureStateJson {
        status: status.to_string(),
        error: if error.is_empty() { None } else { Some(error) },
    };

    Ok(Some(serde_json::to_string(&state).unwrap_or_default()))                                
}

Implementation challenges

No response

@killme2008 killme2008 added the Difficulty: Mid A mid-level task label Feb 22, 2024
@killme2008 killme2008 added this to the v0.7 milestone Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Mid A mid-level task
Projects
None yet
Development

No branches or pull requests

1 participant