[pbs-devel] [PATCH backup 2/4] backup-proxy: avoid block in if condition
Fabian Grünbichler
f.gruenbichler at proxmox.com
Tue Feb 13 11:29:56 CET 2024
On February 13, 2024 10:53 am, Maximiliano Sandoval wrote:
> Fixes the clippy lint:
>
> ```
> warning: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
> --> src/bin/proxmox-backup-proxy.rs:874:58
> |
> 874 | let stats = match tokio::task::spawn_blocking(|| {
> | __________________________________________________________^
> 875 | | let hoststats = collect_host_stats_sync();
> 876 | | let (hostdisk, datastores) = collect_disk_stats_sync();
> 877 | | Arc::new((hoststats, hostdisk, datastores))
> 878 | | })
> | |_________^
> |
> = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions
> = note: `#[warn(clippy::blocks_in_conditions)]` on by default
> ```
>
> Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
> ---
> src/bin/proxmox-backup-proxy.rs | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
> index 9c49026b..b6e1fdd7 100644
> --- a/src/bin/proxmox-backup-proxy.rs
> +++ b/src/bin/proxmox-backup-proxy.rs
> @@ -871,13 +871,12 @@ async fn run_stat_generator() {
> loop {
> let delay_target = Instant::now() + Duration::from_secs(10);
>
> - let stats = match tokio::task::spawn_blocking(|| {
> + let stats_res = tokio::task::spawn_blocking(|| {
nit: called _res , but this is actually the future.. either stats_future, or await it
directly instead of below.
it could also be somewhat simplified by doing
match stats_res {
Ok(stats) => { // do all the broadcasting here },
Err(err) => { // log error here },
};
// sleep here
but that also increases the level of nesting for the broadcasting part,
so it's not a 100% win ;)
> let hoststats = collect_host_stats_sync();
> let (hostdisk, datastores) = collect_disk_stats_sync();
> Arc::new((hoststats, hostdisk, datastores))
> - })
> - .await
> - {
> + });
> + let stats = match stats_res.await {
> Ok(res) => res,
> Err(err) => {
> log::error!("collecting host stats panicked: {err}");
> --
> 2.39.2
>
>
>
> _______________________________________________
> pbs-devel mailing list
> pbs-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
>
>
>
More information about the pbs-devel
mailing list