Implement Outcome::Wait, and CLI on-busy=queue

This commit is contained in:
Félix Saparelli 2021-09-03 09:25:23 +12:00
parent b923638cbd
commit 645ab74c62
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
2 changed files with 30 additions and 23 deletions

View File

@ -100,8 +100,7 @@ fn runtime(args: &ArgMatches<'static>) -> Result<RuntimeConfig> {
} }
if once { if once {
// TODO action.outcome(Outcome::both(Outcome::Start, Outcome::wait(Outcome::Exit)));
// action.outcome(Outcome::both(Outcome::Start, Outcome::both(Outcome::Wait, Outcome::Exit));
return fut; return fut;
} }
@ -125,23 +124,23 @@ fn runtime(args: &ArgMatches<'static>) -> Result<RuntimeConfig> {
if !has_paths { if !has_paths {
if !signals.is_empty() { if !signals.is_empty() {
let mut out = Outcome::DoNothing; let mut out = Outcome::DoNothing;
for sig in signals { for sig in signals {
out = Outcome::both( out = Outcome::both(
out, out,
Outcome::Signal(match sig { Outcome::Signal(match sig {
InputSignal::Hangup => Signal::SIGHUP, InputSignal::Hangup => Signal::SIGHUP,
InputSignal::Interrupt => Signal::SIGINT, InputSignal::Interrupt => Signal::SIGINT,
InputSignal::Quit => Signal::SIGQUIT, InputSignal::Quit => Signal::SIGQUIT,
InputSignal::Terminate => Signal::SIGTERM, InputSignal::Terminate => Signal::SIGTERM,
InputSignal::User1 => Signal::SIGUSR1, InputSignal::User1 => Signal::SIGUSR1,
InputSignal::User2 => Signal::SIGUSR2, InputSignal::User2 => Signal::SIGUSR2,
}), }),
); );
} }
action.outcome(out); action.outcome(out);
return fut; return fut;
} }
let completion = action.events.iter().flat_map(|e| e.completions()).next(); let completion = action.events.iter().flat_map(|e| e.completions()).next();
@ -165,8 +164,8 @@ fn runtime(args: &ArgMatches<'static>) -> Result<RuntimeConfig> {
} }
(false, "restart") => Outcome::both(Outcome::Stop, Outcome::Start), (false, "restart") => Outcome::both(Outcome::Stop, Outcome::Start),
(_, "signal") => Outcome::Signal(signal), (_, "signal") => Outcome::Signal(signal),
// (true, "queue") => Outcome::wait(Outcome::both(Outcome::Clear, Outcome::Start)), (true, "queue") => Outcome::wait(Outcome::both(Outcome::Clear, Outcome::Start)),
// (false, "queue") => Outcome::wait(Outcome::Start), (false, "queue") => Outcome::wait(Outcome::Start),
_ => Outcome::DoNothing, _ => Outcome::DoNothing,
}; };

View File

@ -148,9 +148,9 @@ pub enum Outcome {
/// If the command isn't running, start it. /// If the command isn't running, start it.
Start, Start,
// TODO /// Wait for command completion.
// /// Wait for command completion, then start a new one. Wait,
// Queue,
/// Send this signal to the command. /// Send this signal to the command.
Signal(Signal), Signal(Signal),
@ -182,6 +182,10 @@ impl Outcome {
Self::Both(Box::new(one), Box::new(two)) Self::Both(Box::new(one), Box::new(two))
} }
pub fn wait(and_then: Outcome) -> Self {
Self::Both(Box::new(Outcome::Wait), Box::new(and_then))
}
fn resolve(self, is_running: bool) -> Self { fn resolve(self, is_running: bool) -> Self {
match (is_running, self) { match (is_running, self) {
(true, Self::IfRunning(then, _)) => then.resolve(true), (true, Self::IfRunning(then, _)) => then.resolve(true),
@ -379,6 +383,10 @@ async fn apply_outcome(
p.signal(sig).await; p.signal(sig).await;
} }
(Some(p), Outcome::Wait) => {
p.wait().await?;
}
(_, Outcome::Clear) => { (_, Outcome::Clear) => {
clearscreen::clear()?; clearscreen::clear()?;
} }