diff --git a/crates/turborepo-filewatch/src/cookies.rs b/crates/turborepo-filewatch/src/cookies.rs index e65d9a0e902f3..3e75a1773e6d8 100644 --- a/crates/turborepo-filewatch/src/cookies.rs +++ b/crates/turborepo-filewatch/src/cookies.rs @@ -7,17 +7,17 @@ //! won't get any stale events. //! //! Here's the `CookieWriter` flow: -//! - `CookieWriter` spins up a `watch_cookies` task and creates a +//! - `CookieWriter` spins up a `watch_for_cookie_requests` task and creates a //! `cookie_requests` mpsc channel to send a cookie request to that task. The //! cookie request consists of a oneshot `Sender` that the task can use to //! send back the serial number. -//! - The `watch_cookies` task watches for cookie requests on +//! - The `watch_for_cookie_requests` task watches for cookie requests on //! `cookie_requests_rx`. When one occurs, it creates the cookie file and //! bumps the serial. It then sends the serial back using the `Sender` //! - When `CookieWriter::cookie_request` is called, it sends the cookie request -//! to the `watch_cookies` channel and then waits for the serial as a response -//! (with a timeout). Upon getting the serial, a `CookiedRequest` gets -//! returned with the serial number attached. +//! to the `watch_for_cookie_request` channel and then waits for the serial as +//! a response (with a timeout). Upon getting the serial, a `CookiedRequest` +//! gets returned with the serial number attached. //! //! And here's the `CookieWatcher` flow: //! - `GlobWatcher` creates a `CookieWatcher`. @@ -208,7 +208,8 @@ impl CookieWriter { tracing::debug!("nobody listening for cookie requests, exiting"); return; }; - watch_cookies(root.to_owned(), cookie_requests_rx, exit_signal).await; + watch_for_cookie_file_requests(root.to_owned(), cookie_requests_rx, exit_signal) + .await; } }); Self { @@ -268,7 +269,7 @@ impl CookieWriter { } } -async fn watch_cookies( +async fn watch_for_cookie_file_requests( root: AbsoluteSystemPathBuf, mut cookie_requests: mpsc::Receiver>>, mut exit_signal: mpsc::Receiver<()>, @@ -278,12 +279,12 @@ async fn watch_cookies( tokio::select! { biased; _ = exit_signal.recv() => return, - req = cookie_requests.recv() => handle_cookie_request(&root, &mut serial, req), + req = cookie_requests.recv() => handle_cookie_file_request(&root, &mut serial, req), } } } -fn handle_cookie_request( +fn handle_cookie_file_request( root: &AbsoluteSystemPath, serial: &mut usize, req: Option>>, diff --git a/crates/turborepo-filewatch/src/globwatcher.rs b/crates/turborepo-filewatch/src/globwatcher.rs index 0fbd14b24591c..d82589136eb51 100644 --- a/crates/turborepo-filewatch/src/globwatcher.rs +++ b/crates/turborepo-filewatch/src/globwatcher.rs @@ -118,7 +118,7 @@ impl From for Error { } pub struct GlobWatcher { - cookie_jar: CookieWriter, + cookie_writer: CookieWriter, // _exit_ch exists to trigger a close on the receiver when an instance // of this struct is dropped. The task that is receiving events will exit, // dropping the other sender for the broadcast channel, causing all receivers @@ -163,12 +163,12 @@ struct GlobTracker { impl GlobWatcher { pub fn new( root: AbsoluteSystemPathBuf, - cookie_jar: CookieWriter, + cookie_writer: CookieWriter, mut recv: OptionalWatch>>, ) -> Self { let (exit_ch, exit_signal) = tokio::sync::oneshot::channel(); let (query_ch_tx, query_ch_lazy) = OptionalWatch::new(); - let cookie_root = cookie_jar.root().to_owned(); + let cookie_root = cookie_writer.root().to_owned(); tokio::task::spawn(async move { let Ok(recv) = recv.get().await.map(|r| r.resubscribe()) else { // if this fails, it means that the filewatcher is not available @@ -189,7 +189,7 @@ impl GlobWatcher { .await }); Self { - cookie_jar, + cookie_writer, _exit_ch: exit_ch, query_ch_lazy, } @@ -231,12 +231,13 @@ impl GlobWatcher { candidates, resp: tx, }; + self.send_request(req).await?; tokio::time::timeout(timeout, rx).await?? } async fn send_request(&self, req: Query) -> Result<(), Error> { - let cookied_request = self.cookie_jar.cookie_request(req).await?; + let cookied_request = self.cookie_writer.cookie_request(req).await?; let mut query_ch = self.query_ch_lazy.clone(); let query_ch = query_ch .get_immediate() @@ -507,8 +508,8 @@ mod test { let watcher = FileSystemWatcher::new_with_default_cookie_dir(&repo_root).unwrap(); let recv = watcher.watch(); - let cookie_jar = CookieWriter::new(&cookie_dir, Duration::from_secs(2), recv.clone()); - let glob_watcher = GlobWatcher::new(repo_root.clone(), cookie_jar, recv); + let cookie_writer = CookieWriter::new(&cookie_dir, Duration::from_secs(2), recv.clone()); + let glob_watcher = GlobWatcher::new(repo_root.clone(), cookie_writer, recv); let raw_includes = &["my-pkg/dist/**", "my-pkg/.next/**"]; let raw_excludes = ["my-pkg/.next/cache/**"]; @@ -590,9 +591,9 @@ mod test { let watcher = FileSystemWatcher::new_with_default_cookie_dir(&repo_root).unwrap(); let recv = watcher.watch(); - let cookie_jar = CookieWriter::new(&cookie_dir, Duration::from_secs(2), recv.clone()); + let cookie_writer = CookieWriter::new(&cookie_dir, Duration::from_secs(2), recv.clone()); - let glob_watcher = GlobWatcher::new(repo_root.clone(), cookie_jar, recv); + let glob_watcher = GlobWatcher::new(repo_root.clone(), cookie_writer, recv); let raw_includes = &["my-pkg/dist/**", "my-pkg/.next/**"]; let raw_excludes: [&str; 0] = []; @@ -685,9 +686,9 @@ mod test { let watcher = FileSystemWatcher::new_with_default_cookie_dir(&repo_root).unwrap(); let recv = watcher.watch(); - let cookie_jar = CookieWriter::new(&cookie_dir, Duration::from_secs(2), recv.clone()); + let cookie_writer = CookieWriter::new(&cookie_dir, Duration::from_secs(2), recv.clone()); - let glob_watcher = GlobWatcher::new(repo_root.clone(), cookie_jar, recv); + let glob_watcher = GlobWatcher::new(repo_root.clone(), cookie_writer, recv); // On windows, we expect different sanitization before the // globs are passed in, due to alternative data streams in files.