Skip to content

Commit

Permalink
Merge pull request #12 from tmtmtoo/fix-build
Browse files Browse the repository at this point in the history
maintenance
  • Loading branch information
tmtmtoo authored Dec 31, 2023
2 parents c524a12 + 39521b2 commit b8c1459
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 390 deletions.
677 changes: 343 additions & 334 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ keywords = ["process", "supervisor", "retry", "parallel"]
github = { repository = "tmtmtoo/cx", workflow = "Rust" }

[dependencies]
derive-new = "0.5.8"
derive-getters = "0.1.0"
anyhow = "1.0.32"
tokio = { version = "0.2.22", features = ["rt-threaded", "macros", "time", "process", "io-util", "io-std"] }
async-trait = "0.1.37"
futures = "0.3.5"
structopt = "0.2"
derive-new = "0.6.0"
derive-getters = "0.3.0"
anyhow = "1.0.78"
tokio = { version = "1.35.1", features = ["rt-multi-thread", "macros", "time", "process", "io-util", "io-std"] }
async-trait = "0.1.76"
futures = "0.3.30"
structopt = "0.3.26"

[dev-dependencies]
assert_cmd = "1.0.1"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.46.0
1.75.0
2 changes: 1 addition & 1 deletion src/app/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ impl super::Component for WaitSec {
type Output = ();

async fn handle(&self) -> Self::Output {
tokio::time::delay_for(tokio::time::Duration::from_secs_f64(self.sec)).await
tokio::time::sleep(tokio::time::Duration::from_secs_f64(self.sec)).await
}
}
2 changes: 1 addition & 1 deletion src/app/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ where
State::ExecuteCommand(component) => match self.count {
Some(0) => Transition::Done(RetryResult::Failure),
_ => match (component.handle().await, self.count) {
(Ok(exit), _) if *exit.code() == 0 => Transition::Done(RetryResult::Success),
(anyhow::Result::Ok(exit), _) if *exit.code() == 0 => Transition::Done(RetryResult::Success),
(_, Some(1)) => Transition::Done(RetryResult::Failure),
(_, _) => Transition::Next(RetryApp {
state: State::Sleep(component.into()),
Expand Down
10 changes: 2 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use structopt::clap::AppSettings;
use structopt::StructOpt;

#[derive(Debug, StructOpt, PartialEq)]
#[structopt(author = "")]
#[structopt(raw(setting = "AppSettings::AllowLeadingHyphen"))]
#[derive(Debug, structopt::StructOpt, PartialEq)]
#[structopt(setting = structopt::clap::AppSettings::AllowLeadingHyphen)]
/// Command eXecutor
pub enum Config {
/// Retry command execution until successful.
#[structopt(author = "")]
retry {
/// maximum number of retry counts
#[structopt(short, long)]
Expand All @@ -22,7 +17,6 @@ pub enum Config {
command: Vec<String>,
},
/// Supervise command execution.
#[structopt(author = "")]
supervise {
/// re-execution limit counts
#[structopt(short, long)]
Expand Down
4 changes: 2 additions & 2 deletions src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub struct Exit {
stderr_wrote_length: Option<u64>,
}

trait AsyncReadUnpin: AsyncRead + Unpin + Send {}
trait AsyncReadUnpin: tokio::io::AsyncRead + Unpin + Send {}

trait AsyncWriteUnpin: AsyncWrite + Unpin + Send {}
trait AsyncWriteUnpin: tokio::io::AsyncWrite + Unpin + Send {}

trait ChildProcess: std::future::Future<Output = Result<i32>> + Unpin + Send {
fn stdout(&mut self) -> Result<Box<dyn AsyncReadUnpin>>;
Expand Down
4 changes: 2 additions & 2 deletions src/exec/child_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ impl Future for TokioChildProcess {
) -> std::task::Poll<Self::Output> {
use futures::prelude::*;

self.0
self.0.wait().boxed()
.poll_unpin(cx)
.map(|status| match status.map(|status| status.code()) {
Ok(Some(code)) => Ok(code),
anyhow::Result::Ok(Some(code)) => Ok(code),
_ => Err(anyhow!(
"failed to start child process or terminated abnormally"
)),
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// https://doc.rust-lang.org/stable/rustc/lints/listing/warn-by-default.html
#![deny(const_err)]
#![deny(non_shorthand_field_patterns)]
#![deny(non_snake_case)]
#![deny(non_upper_case_globals)]
Expand Down
1 change: 0 additions & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ pub use async_trait::*;
pub use core::future::*;
pub use futures::{future::Either, FutureExt};
pub use std::sync::Arc;
pub use tokio::prelude::*;
16 changes: 0 additions & 16 deletions tests/retry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use assert_cmd::Command;
use predicates::prelude::*;

#[cfg(not(target_os = "windows"))]
#[test]
fn successful_1_time() {
let mut cmd = Command::cargo_bin("cx").unwrap();
Expand All @@ -19,21 +18,6 @@ fn successful_1_time() {
));
}

#[cfg(target_os = "windows")]
#[test]
fn successful_1_time() {
let mut cmd = Command::cargo_bin("cx").unwrap();

cmd.arg("retry")
.arg("-c")
.arg("2")
.arg("--")
.arg("echo abc")
.assert()
.success()
.stdout(predicate::eq("abc\r\n"));
}

#[test]
fn failed_2_time() {
let mut cmd = Command::cargo_bin("cx").unwrap();
Expand Down
16 changes: 0 additions & 16 deletions tests/supervise.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use assert_cmd::Command;
use predicates::prelude::*;

#[cfg(not(target_os = "windows"))]
#[test]
fn echo_2_times() {
let mut cmd = Command::cargo_bin("cx").unwrap();
Expand All @@ -16,21 +15,6 @@ fn echo_2_times() {
.stdout(predicate::eq("abc\nabc\n"));
}

#[cfg(target_os = "windows")]
#[test]
fn echo_2_times() {
let mut cmd = Command::cargo_bin("cx").unwrap();

cmd.arg("supervise")
.arg("-c")
.arg("2")
.arg("--")
.arg("echo abc")
.assert()
.success()
.stdout(predicate::eq("abc\r\nabc\r\n"));
}

#[test]
fn sleep_one_time() {
let mut cmd = Command::cargo_bin("cx").unwrap();
Expand Down

0 comments on commit b8c1459

Please sign in to comment.