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

fix: separate watch loop for the non-interactive mode #3979

Merged
merged 2 commits into from
Mar 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 37 additions & 6 deletions applications/tari_base_node/src/commands/cli_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ impl CliLoop {
pub async fn cli_loop(mut self) {
cli::print_banner(self.commands.clone(), 3);

// TODO: Check for a new version here
while !self.done {
self.watch_loop().await;
if self.non_interactive {
break;
if self.non_interactive {
self.watch_loop_non_interactive().await;
} else {
// TODO: Check for a new version here
while !self.done {
self.watch_loop().await;
self.execute_command().await;
}
self.execute_command().await;
}
}

Expand Down Expand Up @@ -164,6 +165,36 @@ impl CliLoop {
}
}

async fn watch_loop_non_interactive(&mut self) {
if let Some(command) = self.watch_task.take() {
let mut interrupt = signal::ctrl_c().fuse().boxed();
let config = self.context.config.clone();
let line = command.line();
let interval = command
.interval
.map(Duration::from_secs)
.unwrap_or(config.base_node_status_line_interval);
if let Err(err) = self.context.handle_command_str(line).await {
println!("Wrong command to watch `{}`. Failed with: {}", line, err);
} else {
loop {
let interval = time::sleep(interval);
tokio::select! {
_ = interval => {
if let Err(err) = self.context.handle_command_str(line).await {
println!("Watched command `{}` failed: {}", line, err);
}
continue;
},
_ = &mut interrupt => {
break;
}
}
}
}
}
}

async fn handle_line(&mut self, line: String) {
// Reset the interruption flag if the command entered.
self.first_signal = false;
Expand Down