Simplify on_update code further

This commit is contained in:
Félix Saparelli 2021-04-11 04:02:14 +12:00
parent d25c374d7f
commit e08f1934ec
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
1 changed files with 8 additions and 7 deletions

View File

@ -229,33 +229,34 @@ impl Handler for ExecHandler {
// Only returns Err() on lock poisoning.
fn on_update(&self, ops: &[PathOp]) -> Result<bool> {
let signal = self.signal.unwrap_or(Signal::SIGTERM);
match (
self.has_running_process(),
self.args.on_busy_update,
self.signal,
) {
// If nothing is running, start the command
(false, _, _) => {
(false, _) => {
self.spawn(ops)?;
}
// Just send a signal to the command, do nothing more
(true, OnBusyUpdate::Signal, signal) => signal_process(&self.child_process, signal.unwrap_or(Signal::SIGTERM)),
(true, OnBusyUpdate::Signal) => signal_process(&self.child_process, signal),
// Send a signal to the command, wait for it to exit, then run the command again
(true, OnBusyUpdate::Restart, signal) => {
signal_process(&self.child_process, signal.unwrap_or(Signal::SIGTERM));
(true, OnBusyUpdate::Restart) => {
signal_process(&self.child_process, signal);
wait_on_process(&self.child_process);
self.spawn(ops)?;
}
// Wait for the command to end, then run it again
(true, OnBusyUpdate::Queue, _) => {
(true, OnBusyUpdate::Queue) => {
wait_on_process(&self.child_process);
self.spawn(ops)?;
}
(true, OnBusyUpdate::DoNothing, _) => {}
(true, OnBusyUpdate::DoNothing) => {}
}
// Handle once option for integration testing