From 144db63e1a66ed43d107353e904d1410f59b51dd Mon Sep 17 00:00:00 2001 From: "nieznany.sprawiciel" Date: Mon, 29 Jul 2024 13:22:03 +0200 Subject: [PATCH] Adjust Runtime::test function --- src/main.rs | 8 ++++++-- src/process.rs | 11 +++++------ src/process/automatic.rs | 8 ++++++++ src/process/dummy.rs | 2 +- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 55f18cd..2f70fd6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use std::rc::Rc; use std::time::Duration; use actix::prelude::*; -use anyhow::Context; +use anyhow::{anyhow, Context}; use chrono::Utc; use clap::Parser; use futures::prelude::*; @@ -243,7 +243,11 @@ async fn run( io::stdout().write_all(offer_template.as_bytes())?; return Ok(()); } - Command::Test => return RUNTIME::test(&runtime_config), + Command::Test => { + return RUNTIME::test(runtime_config.clone()) + .await + .map_err(|e| anyhow!("Testing runtime failed: {e}")) + } }; let runtime_config = Box::pin(runtime_config); diff --git a/src/process.rs b/src/process.rs index 57af461..b3fb8c7 100644 --- a/src/process.rs +++ b/src/process.rs @@ -32,7 +32,7 @@ pub struct Usage { } #[async_trait] -pub(crate) trait Runtime: Sized { +pub(crate) trait Runtime: Sized + Send { type CONFIG: RuntimeConfig; fn parse_config(config: &Option) -> anyhow::Result { @@ -48,10 +48,9 @@ pub(crate) trait Runtime: Sized { async fn wait(&mut self) -> std::io::Result; - fn test(config: &Self::CONFIG) -> anyhow::Result<()> { - gpu_detection(config).map_err(|err| { - anyhow::anyhow!("Testing runtime failed. Unable to detect GPU. Error: {err}") - })?; + async fn test(config: Self::CONFIG) -> anyhow::Result<()> { + gpu_detection(&config) + .map_err(|err| anyhow::anyhow!("Unable to detect GPU. Error: {err}"))?; Ok(()) } @@ -66,7 +65,7 @@ pub(crate) trait Runtime: Sized { } } -pub(crate) trait RuntimeConfig: DeserializeOwned + Default + Debug + Clone { +pub(crate) trait RuntimeConfig: DeserializeOwned + Default + Debug + Clone + Send { fn gpu_uuid(&self) -> Option; } diff --git a/src/process/automatic.rs b/src/process/automatic.rs index ae97308..f1f956f 100644 --- a/src/process/automatic.rs +++ b/src/process/automatic.rs @@ -15,6 +15,7 @@ use tokio::{ time::timeout, }; +use crate::offer_template::gpu_detection; use std::{ path::PathBuf, process::{ExitStatus, Stdio}, @@ -60,6 +61,13 @@ impl Runtime for Automatic { }) } + async fn test(config: Self::CONFIG) -> anyhow::Result<()> { + gpu_detection(&config) + .map_err(|err| anyhow::anyhow!("Unable to detect GPU. Error: {err}"))?; + + Ok(()) + } + async fn stop(&mut self) -> anyhow::Result<()> { log::info!("Stopping Automatic server"); let client = reqwest::Client::new(); diff --git a/src/process/dummy.rs b/src/process/dummy.rs index b1c012a..2e14e50 100644 --- a/src/process/dummy.rs +++ b/src/process/dummy.rs @@ -86,7 +86,7 @@ impl Runtime for Dummy { child.wait().await } - fn test(_config: &Self::CONFIG) -> anyhow::Result<()> { + async fn test(_config: Self::CONFIG) -> anyhow::Result<()> { Ok(()) }