Skip to content

Commit

Permalink
fix: separate watch loop for the non-interactive mode (#3979)
Browse files Browse the repository at this point in the history
Description
---
The PR adds the separate loop for the `watch` command in the non-interactive mode.

Motivation and Context
---
The new `CliLoop` struct uses the same routine in both: interactive and non-interactive mode,
but it failed if started under `systemd`.

How Has This Been Tested?
---
Manually
  • Loading branch information
therustmonk authored Mar 31, 2022
1 parent 8b11c51 commit 9bf6503
Showing 1 changed file with 37 additions and 6 deletions.
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

0 comments on commit 9bf6503

Please sign in to comment.