Skip to content

Commit

Permalink
Adjust Runtime::test function
Browse files Browse the repository at this point in the history
  • Loading branch information
nieznanysprawiciel committed Jul 29, 2024
1 parent a8b4d45 commit 144db63
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -243,7 +243,11 @@ async fn run<RUNTIME: process::Runtime + Clone + Unpin + 'static>(
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);
Expand Down
11 changes: 5 additions & 6 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value>) -> anyhow::Result<Self::CONFIG> {
Expand All @@ -48,10 +48,9 @@ pub(crate) trait Runtime: Sized {

async fn wait(&mut self) -> std::io::Result<ExitStatus>;

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(())
}

Expand All @@ -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<String>;
}

Expand Down
8 changes: 8 additions & 0 deletions src/process/automatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use tokio::{
time::timeout,
};

use crate::offer_template::gpu_detection;
use std::{
path::PathBuf,
process::{ExitStatus, Stdio},
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/process/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down

0 comments on commit 144db63

Please sign in to comment.