(
cmd: Command,
wc: WatcherConfig,
ext_cache: ExtensionCache,
)
| 88 | } |
| 89 | |
| 90 | async fn runtime( |
| 91 | cmd: Command, |
| 92 | wc: WatcherConfig, |
| 93 | ext_cache: ExtensionCache, |
| 94 | ) -> Result<RuntimeConfig, ServerError> { |
| 95 | let mut config = RuntimeConfig::default(); |
| 96 | |
| 97 | config.pathset([wc.base.clone()]); |
| 98 | config.commands(vec![cmd]); |
| 99 | |
| 100 | config.filterer(create_filter(&wc.base, &wc.ignore_files, wc.ignore_changes).await?); |
| 101 | |
| 102 | config.action_throttle(Duration::from_secs(3)); |
| 103 | |
| 104 | config.on_action(move |action: Action| { |
| 105 | let signals: Vec<MainSignal> = action.events.iter().flat_map(|e| e.signals()).collect(); |
| 106 | let has_paths = action |
| 107 | .events |
| 108 | .iter() |
| 109 | .flat_map(|e| e.paths()) |
| 110 | .next() |
| 111 | .is_some(); |
| 112 | |
| 113 | let empty_event = action |
| 114 | .events |
| 115 | .iter() |
| 116 | .map(|e| e.is_empty()) |
| 117 | .next() |
| 118 | .unwrap_or_default(); |
| 119 | |
| 120 | debug!( |
| 121 | ?action, |
| 122 | ?signals, |
| 123 | has_paths, |
| 124 | empty_event, |
| 125 | "watcher action received" |
| 126 | ); |
| 127 | |
| 128 | let ext_cache = ext_cache.clone(); |
| 129 | async move { |
| 130 | if signals.contains(&MainSignal::Terminate) { |
| 131 | let function_shutdown_delay = ext_cache.function_shutdown_delay().await; |
| 132 | if let Some(delay) = function_shutdown_delay { |
| 133 | function_graceful_shutdown_or_else_sigkill( |
| 134 | action, |
| 135 | MainSignal::Terminate, |
| 136 | delay, |
| 137 | ); |
| 138 | return Ok(()); |
| 139 | } |
| 140 | action.outcome(Outcome::both(Outcome::Stop, Outcome::Exit)); |
| 141 | return Ok(()); |
| 142 | } |
| 143 | if signals.contains(&MainSignal::Interrupt) { |
| 144 | let function_shutdown_delay = ext_cache.function_shutdown_delay().await; |
| 145 | if let Some(delay) = function_shutdown_delay { |
| 146 | function_graceful_shutdown_or_else_sigkill( |
| 147 | action, |
no test coverage detected