Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(composition): general cleanup #2213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/composition/run_composition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,14 @@ mod tests {
.read_file(mock_read_file)
.build();

let subgraph_change_events: BoxStream<SubgraphEvent> =
once(async { SubgraphEvent::SubgraphChanged(SubgraphSchemaChanged::default()) })
.boxed();
let subgraph_change_events: BoxStream<SubgraphEvent> = once(async {
SubgraphEvent::SubgraphChanged(SubgraphSchemaChanged::new(
"some-name".to_string(),
"some sdl".to_string(),
))
})
.boxed();

let (mut composition_messages, composition_subtask) = Subtask::new(composition_handler);
let abort_handle = composition_subtask.run(subgraph_change_events);

Expand Down
34 changes: 22 additions & 12 deletions src/composition/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,21 @@ pub enum SubgraphEvent {
}
/// An event denoting that the subgraph has changed, emitting its name and the SDL reflecting that
/// change
#[derive(derive_getters::Getters, Default)]
#[derive(derive_getters::Getters)]
pub struct SubgraphSchemaChanged {
/// Subgraph name
name: String,
/// SDL with changes
sdl: String,
}

#[cfg(test)]
impl SubgraphSchemaChanged {
pub fn new(name: String, sdl: String) -> Self {
Self { name, sdl }
}
}

/// The subgraph is no longer watched
#[derive(derive_getters::Getters, Default)]
pub struct SubgraphSchemaRemoved {
Expand Down Expand Up @@ -309,17 +316,20 @@ impl SubtaskHandleStream for SubgraphWatchers {
Subtask::<SubgraphWatcher, WatchedSdlChange>::new(subgraph_watcher);

let sender = sender.clone();
let subgraph_name_c = subgraph_name.clone();
let messages_abort_handle = tokio::spawn(async move {
while let Some(change) = messages.next().await {
let _ = sender
.send(SubgraphEvent::SubgraphChanged(
SubgraphSchemaChanged {
name: subgraph_name_c.to_string(),
sdl: change.sdl().to_string(),
},
))
.tap_err(|err| tracing::error!("{:?}", err));
let messages_abort_handle = tokio::spawn({
let subgraph_name = subgraph_name.clone();

async move {
while let Some(change) = messages.next().await {
let _ = sender
.send(SubgraphEvent::SubgraphChanged(
SubgraphSchemaChanged {
name: subgraph_name.to_string(),
sdl: change.sdl().to_string(),
},
))
.tap_err(|err| tracing::error!("{:?}", err));
}
}
})
.abort_handle();
Expand Down
Loading