Skip to content

Commit

Permalink
Changed the protobuf format slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Mar 5, 2024
1 parent eefaf1c commit 4183911
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
12 changes: 10 additions & 2 deletions crates/turborepo-lib/src/daemon/proto/turbod.proto
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,18 @@ message DiscoverPackagesRequest {
message PackageChangesRequest {}

message PackageChangeEvent {
PackageChangeType change_type = 1;
optional string package_name = 2;
oneof event {
PackageChanged package_changed = 1;
RediscoverPackages rediscover_packages = 2;
}
}

message PackageChanged {
string package_name = 1;
}

message RediscoverPackages {}

enum PackageChangeType {
Package = 0;
Rediscover = 1;
Expand Down
20 changes: 16 additions & 4 deletions crates/turborepo-lib/src/daemon/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,14 @@ impl<PD: PackageDiscovery + Send + Sync + 'static> proto::turbod_server::Turbod
let mut package_changes_rx = self.file_watching.package_changes_watcher.package_changes();
let (tx, rx) = mpsc::channel(1);

tx.send(Ok(proto::PackageChangeEvent {
event: Some(proto::package_change_event::Event::RediscoverPackages(
proto::RediscoverPackages {},
)),
}))
.await
.map_err(|e| tonic::Status::unavailable(format!("{}", e)))?;

tokio::spawn(async move {
loop {
if let Err(err) = package_changes_rx.changed().await {
Expand All @@ -592,12 +600,16 @@ impl<PD: PackageDiscovery + Send + Sync + 'static> proto::turbod_server::Turbod

let event = match &*package_changes_rx.borrow() {
PackageChangeEvent::Package { name } => proto::PackageChangeEvent {
change_type: proto::PackageChangeType::Package as i32,
package_name: Some(name.to_string()),
event: Some(proto::package_change_event::Event::PackageChanged(
proto::PackageChanged {
package_name: name.to_string(),
},
)),
},
PackageChangeEvent::Rediscover => proto::PackageChangeEvent {
change_type: proto::PackageChangeType::Rediscover as i32,
package_name: None,
event: Some(proto::package_change_event::Event::RediscoverPackages(
proto::RediscoverPackages {},
)),
},
};

Expand Down
5 changes: 2 additions & 3 deletions crates/turborepo-lib/src/run/scope/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,15 +588,14 @@ mod test {
use test_case::test_case;
use turbopath::{AbsoluteSystemPathBuf, AnchoredSystemPathBuf, RelativeUnixPathBuf};
use turborepo_repository::{
change_mapper::ChangeMapError,
discovery::PackageDiscovery,
package_graph::{PackageGraph, PackageName, ROOT_PKG_NAME},
package_json::PackageJson,
package_manager::PackageManager,
};

use super::{FilterResolver, PackageInference, TargetSelector};
use crate::run::scope::change_detector::GitChangeDetector;
use crate::run::scope::{change_detector::GitChangeDetector, ResolutionError};

fn get_name(name: &str) -> (Option<&str>, &str) {
if let Some(idx) = name.rfind('/') {
Expand Down Expand Up @@ -1159,7 +1158,7 @@ mod test {
&self,
from: &str,
to: &str,
) -> Result<HashSet<PackageName>, ChangeMapError> {
) -> Result<HashSet<PackageName>, ResolutionError> {
Ok(self
.0
.get(&(from, to))
Expand Down
13 changes: 7 additions & 6 deletions crates/turborepo-lib/src/run/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ impl WatchClient {
while let Some(hash) = hashes.next().await {
// Should we recover here?
let hash = hash.unwrap();
match proto::PackageChangeType::try_from(hash.change_type).unwrap() {
proto::PackageChangeType::Package => {
if let Some(package) = hash.package_name {
println!("{} changed", package);
}
let event = hash.event.expect("event is missing");
match event {
proto::package_change_event::Event::PackageChanged(proto::PackageChanged {
package_name,
}) => {
println!("{} changed", package_name);
}
proto::PackageChangeType::Rediscover => {
proto::package_change_event::Event::RediscoverPackages(_) => {
println!("Rediscovering packages");
}
}
Expand Down

0 comments on commit 4183911

Please sign in to comment.