Skip to content

Commit

Permalink
compilation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
prekucki committed Oct 18, 2023
1 parent 7e018b4 commit 8e2da57
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 36 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ ya-runtime-api= { git = "https://github.com/golemfactory/yagna.git", branch="rel
ya-client-model = "0.5.0"

regex = "1"
reqwest="0.11.22"
11 changes: 4 additions & 7 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Exe-Unit Cli Definitions
//!
use std::path::PathBuf;
use clap::{Parser, Subcommand};
use std::path::PathBuf;

#[derive(Parser, Debug)]
#[command(author, version, about)]
Expand All @@ -14,7 +14,6 @@ pub struct Cli {
pub command: Command,
}


#[derive(Subcommand, Debug)]
pub enum Command {
/// Bind to Service Bus
Expand All @@ -31,7 +30,7 @@ pub enum Command {
/// Print an offer template in JSON format
OfferTemplate,
/// Run runtime's test command
Test
Test,
}

#[derive(Parser, Debug)]
Expand All @@ -49,15 +48,13 @@ pub struct RunArgs {

#[cfg(test)]
mod test {
use std::path::Path;
use super::*;
use std::path::Path;

#[test]
fn test_args() {
let cli = Cli::parse_from(["-b", "/tmp/false-runtime", "offer-template"]);
assert_eq!(cli.binary, Some(Path::new("/tmp/false-runtime")));
assert!(matches!(cli.command, Command::OfferTemplate));
}


}
}
45 changes: 24 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use std::cell::RefCell;
use std::collections::HashMap;
use std::io::Write;
use std::pin::pin;
use std::rc::Rc;
use std::time::Duration;
use std::{env, io};
use std::pin::pin;

use chrono::Utc;
use clap::Parser;
Expand Down Expand Up @@ -98,26 +98,25 @@ async fn activity_loop<T: process::MinerEngine + Clone + Unpin + 'static>(
log::debug!("Looping2 ...");

let sleep = pin!(actix_rt::time::sleep(Duration::from_secs(1)));
process =
match future::select(sleep, process).await {
future::Either::Left((_, p)) => p,
future::Either::Right((status, _)) => {
let _err = report_service
.call(activity::local::SetState {
activity_id: activity_id.to_string(),
state: ActivityState {
state: StatePair::from(State::Terminated),
reason: Some("process exit".to_string()),
error_message: Some(format!("status: {:?}", status)),
},
timeout: None,
credentials: None,
})
.await;
log::error!("process exit: {:?}", status);
anyhow::bail!("Miner app exited")
}
process = match future::select(sleep, process).await {
future::Either::Left((_, p)) => p,
future::Either::Right((status, _)) => {
let _err = report_service
.call(activity::local::SetState {
activity_id: activity_id.to_string(),
state: ActivityState {
state: StatePair::from(State::Terminated),
reason: Some("process exit".to_string()),
error_message: Some(format!("status: {:?}", status)),
},
timeout: None,
credentials: None,
})
.await;
log::error!("process exit: {:?}", status);
anyhow::bail!("Miner app exited")
}
}
}
Ok(())
}
Expand Down Expand Up @@ -155,6 +154,10 @@ async fn run<T: process::MinerEngine + Clone + Unpin + 'static>() -> anyhow::Res
io::stdout().write_all(offer_template::template()?.as_ref())?;
return Ok(());
}
Command::Test => {
// Test
return Ok(());
}
};

env_logger::builder().format_indent(Some(4)).init();
Expand Down Expand Up @@ -188,7 +191,7 @@ async fn run<T: process::MinerEngine + Clone + Unpin + 'static>() -> anyhow::Res
let mut result = Vec::new();
for exe in &exec.exe_script {
match exe {
ExeScriptCommand::Deploy {} => {
ExeScriptCommand::Deploy { .. } => {
send_state(
&report_url,
&activity_id,
Expand Down
15 changes: 9 additions & 6 deletions src/process.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use clap::Parser;
use std::cell::RefCell;
use std::env::current_exe;
use std::future::Future;
use std::marker::PhantomData;
use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::pin::{pin, Pin};
use std::process::ExitStatus;
use std::rc::Rc;
use std::task::{Context, Poll};
use clap::Parser;

use futures::prelude::*;
use tokio::process::*;

pub use self::phoenix::Phoenix;
Expand Down Expand Up @@ -51,7 +51,7 @@ pub struct MiningAppArgs {
impl MiningAppArgs {
pub fn new(args: &[String]) -> anyhow::Result<Self> {
let me = "gminer".to_string();
Ok(Self::from_iter_safe(std::iter::once(&me).chain(args))?)
Ok(Self::try_parse_from(std::iter::once(&me).chain(args))?)
}
}

Expand Down Expand Up @@ -127,7 +127,7 @@ impl<T: MinerEngine + Clone + 'static> ProcessController<T> {
invalid_shares,
});
if let ProcessControllerInner::Working { mut child, .. } = old {
let _ = child.kill();
let _ = child.kill().await;
}
}

Expand Down Expand Up @@ -175,7 +175,10 @@ impl<T> Future for ProcessController<T> {

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match *self.inner.borrow_mut() {
ProcessControllerInner::Working { ref mut child, .. } => child.poll_unpin(cx),
ProcessControllerInner::Working { ref mut child, .. } => {
let fut = pin!(child.wait());
fut.poll(cx)
}
_ => Poll::Pending,
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/process/win.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::mem;
use std::ptr;
#[cfg(target_os = "windows")]
use winapi::shared::minwindef::{DWORD, LPVOID};
#[cfg(target_os = "windows")]
Expand Down

0 comments on commit 8e2da57

Please sign in to comment.