-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(composition): adding composition events, move types around, TODO'…
…d impl of `SubtaskHandleStream` for `Composition` (#2131) Co-authored-by: Brian George <[email protected]>
- Loading branch information
1 parent
bdb8186
commit 7586992
Showing
6 changed files
with
110 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use super::{CompositionError, CompositionSuccess}; | ||
|
||
/// Events emitted from composition | ||
pub enum CompositionEvent { | ||
/// The composition has started and may not have finished yet. This is useful for letting users | ||
/// know composition is running | ||
Started, | ||
/// Composition succeeded | ||
Success(CompositionSuccess), | ||
/// Composition errored | ||
Error(CompositionError), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,84 @@ | ||
use std::fmt::Debug; | ||
|
||
use apollo_federation_types::{ | ||
build::{BuildErrors, BuildHint}, | ||
config::FederationVersion, | ||
}; | ||
use camino::Utf8PathBuf; | ||
use derive_getters::Getters; | ||
use events::CompositionEvent; | ||
use supergraph::{ | ||
binary::{OutputTarget, SupergraphBinary}, | ||
Check warning on line 11 in src/composition/mod.rs GitHub Actions / Build Rover for macOS x86-64
|
||
config::ResolvedSupergraphConfig, | ||
}; | ||
use watchers::subtask::{SubtaskHandleStream, SubtaskRunStream}; | ||
Check warning on line 14 in src/composition/mod.rs GitHub Actions / Build Rover for macOS x86-64
|
||
|
||
use crate::utils::effect::{exec::ExecCommand, read_file::ReadFile}; | ||
Check warning on line 16 in src/composition/mod.rs GitHub Actions / Build Rover for macOS x86-64
|
||
|
||
pub mod events; | ||
pub mod supergraph; | ||
|
||
#[cfg(feature = "composition-js")] | ||
mod watchers; | ||
|
||
#[derive(Getters, Debug, Clone, Eq, PartialEq)] | ||
pub struct CompositionSuccess { | ||
supergraph_sdl: String, | ||
hints: Vec<BuildHint>, | ||
federation_version: FederationVersion, | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum CompositionError { | ||
#[error("Failed to run the composition binary")] | ||
Binary { error: Box<dyn Debug> }, | ||
#[error("Failed to parse output of `{binary} compose`")] | ||
InvalidOutput { | ||
binary: Utf8PathBuf, | ||
error: Box<dyn Debug>, | ||
}, | ||
#[error("Invalid input for `{binary} compose`")] | ||
InvalidInput { | ||
binary: Utf8PathBuf, | ||
error: Box<dyn Debug>, | ||
}, | ||
#[error("Failed to read the file at: {path}")] | ||
ReadFile { | ||
path: Utf8PathBuf, | ||
error: Box<dyn Debug>, | ||
}, | ||
#[error("Encountered {} while trying to build a supergraph.", .source.length_string())] | ||
Build { | ||
source: BuildErrors, | ||
// NB: in do_compose (rover_client/src/error -> BuildErrors) this includes num_subgraphs, | ||
// but this is only important if we end up with a RoverError (it uses a singular or plural | ||
// error message); so, leaving TBD if we go that route because it'll require figuring out | ||
// from something like the supergraph_config how many subgraphs we attempted to compose | ||
// (alternatively, we could just reword the error message to allow for either) | ||
}, | ||
} | ||
|
||
// NB: this is where we'll contain the logic for kicking off watchers | ||
struct Composition {} | ||
Check warning on line 62 in src/composition/mod.rs GitHub Actions / Build Rover for macOS x86-64
|
||
// TODO: replace with an enum of watchers' and their events | ||
struct SomeWatcherEventReplaceMe {} | ||
|
||
// NB: this is where we'll bring it all together to actually watch incoming events from watchers to | ||
// decide whether we need to recompose/etc | ||
impl SubtaskHandleStream for Composition { | ||
type Input = SomeWatcherEventReplaceMe; | ||
type Output = CompositionEvent; | ||
|
||
fn handle( | ||
self, | ||
sender: tokio::sync::mpsc::UnboundedSender<Self::Output>, | ||
Check warning on line 74 in src/composition/mod.rs GitHub Actions / Build Rover for macOS x86-64
|
||
input: futures::stream::BoxStream<'static, Self::Input>, | ||
Check warning on line 75 in src/composition/mod.rs GitHub Actions / Build Rover for macOS x86-64
|
||
) -> tokio::task::AbortHandle { | ||
tokio::spawn(async move { | ||
// TODO: wait on the watchers | ||
// TODO: compose if necessary | ||
// TODO: emit event | ||
}) | ||
.abort_handle() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters