Skip to content

Commit 8867ea2

Browse files
phil-oppchrislearn
authored andcommitted
Error if node with git field was not built before dataflow start
The working directory of nodes with git fields is only decided on `dora build` because that's where we translate the branch/tag name into the commit hash. Before, we fell back to using the base working directory if no build was done. However, this is confusing since the reason for the different working directory is not communicated in any. This commit throws an error if no build happened before starting a dataflow with git nodes.
1 parent 7749739 commit 8867ea2

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

binaries/daemon/src/lib.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,8 +1123,19 @@ impl Daemon {
11231123

11241124
let mut stopped = Vec::new();
11251125

1126-
let node_working_dirs = build_id
1127-
.and_then(|build_id| self.builds.get(&build_id))
1126+
let build_info = build_id.and_then(|build_id| self.builds.get(&build_id));
1127+
let node_with_git_source = nodes.values().find(|n| n.has_git_source());
1128+
if let Some(git_node) = node_with_git_source {
1129+
if build_info.is_none() {
1130+
eyre::bail!(
1131+
"node {} has git source, but no `dora build` was run yet\n\n\
1132+
nodes with a `git` field must be built using `dora build` before starting the \
1133+
dataflow",
1134+
git_node.id
1135+
)
1136+
}
1137+
}
1138+
let node_working_dirs = build_info
11281139
.map(|info| info.node_working_dirs.clone())
11291140
.unwrap_or_default();
11301141

@@ -1192,12 +1203,16 @@ impl Daemon {
11921203
.entry(node.id.clone())
11931204
.or_insert_with(|| Arc::new(ArrayQueue::new(STDERR_LOG_LINES)))
11941205
.clone();
1195-
logger
1196-
.log(LogLevel::Info, Some("daemon".into()), "spawning")
1197-
.await;
1198-
let node_working_dir = node_working_dirs
1199-
.get(&node_id)
1200-
.cloned()
1206+
1207+
let configured_node_working_dir = node_working_dirs.get(&node_id).cloned();
1208+
if configured_node_working_dir.is_none() && node.has_git_source() {
1209+
eyre::bail!(
1210+
"node {} has git source, but no git clone directory was found for it\n\n\
1211+
try running `dora build` again",
1212+
node.id
1213+
)
1214+
}
1215+
let node_working_dir = configured_node_working_dir
12011216
.or_else(|| {
12021217
node.deploy
12031218
.as_ref()

libraries/message/src/descriptor.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,15 @@ pub struct ResolvedNode {
482482
pub kind: CoreNodeKind,
483483
}
484484

485+
impl ResolvedNode {
486+
pub fn has_git_source(&self) -> bool {
487+
self.kind
488+
.as_custom()
489+
.map(|n| n.source.is_git())
490+
.unwrap_or_default()
491+
}
492+
}
493+
485494
#[derive(Debug, Clone, Serialize, Deserialize)]
486495
#[serde(rename_all = "lowercase")]
487496
#[allow(clippy::large_enum_variant)]
@@ -492,6 +501,15 @@ pub enum CoreNodeKind {
492501
Custom(CustomNode),
493502
}
494503

504+
impl CoreNodeKind {
505+
pub fn as_custom(&self) -> Option<&CustomNode> {
506+
match self {
507+
CoreNodeKind::Runtime(_) => None,
508+
CoreNodeKind::Custom(custom_node) => Some(custom_node),
509+
}
510+
}
511+
}
512+
495513
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
496514
#[serde(transparent)]
497515
pub struct RuntimeNode {
@@ -640,6 +658,12 @@ pub enum NodeSource {
640658
},
641659
}
642660

661+
impl NodeSource {
662+
pub fn is_git(&self) -> bool {
663+
matches!(self, Self::GitBranch { .. })
664+
}
665+
}
666+
643667
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
644668
pub enum ResolvedNodeSource {
645669
Local,

0 commit comments

Comments
 (0)