Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: convert to duration only one time instead of every loop run #20

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Duration;

use clap::{App, Arg};

mod error;
Expand Down Expand Up @@ -81,7 +83,7 @@ fn main() -> Result<()> {
let waitz = Waitz {
command,
args,
interval,
interval: Duration::from_millis(interval),
no_retry,
logger,
};
Expand Down
12 changes: 5 additions & 7 deletions src/waitz.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::process::{Command, ExitStatus};
use std::{thread, time};
use std::{thread, time::Duration};

use crate::error::Result;
use crate::logger::Logger;
Expand All @@ -8,7 +8,7 @@ use crate::logger::Logger;
pub struct Waitz<'a> {
pub command: &'a str,
pub args: Vec<&'a str>,
pub interval: u64,
pub interval: Duration,
pub no_retry: bool,
pub logger: Logger,
}
Expand All @@ -18,11 +18,9 @@ impl Waitz<'_> {
self.logger.debug(&format!("{:?}", &self));

while !is_successful(self.command, &self.args, &self.logger) && !self.no_retry {
self.logger.verbose(&format!(
"Wait for {:?} milliseconds to run again",
self.interval
));
thread::sleep(time::Duration::from_millis(self.interval));
self.logger
.verbose(&format!("Wait for {:?} to run again", self.interval));
thread::sleep(self.interval);
}
}
}
Expand Down