Skip to content

Commit

Permalink
Implement custom maybe_return_early for execute
Browse files Browse the repository at this point in the history
Otherwise the trait default prevents the resource from running when it
is being triggered by a resource that has just been deleted.
  • Loading branch information
puetzp committed Feb 15, 2025
1 parent deb51b4 commit 121f6d8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
24 changes: 24 additions & 0 deletions client/src/resources/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ impl ResourceTrait for Execute {
fn is_present(&self) -> bool {
self.parameters.ensure.is_present()
}

fn maybe_return_early(&self, applied_resources: &HashMap<Uuid, Resource>) -> Option<Action> {
if let Some(dependency) = self.find_failed_dependency(applied_resources) {
log::warn!(
"`{}`: skipping resource as dependency `{}` has failed to apply",
self.repr(),
dependency.repr()
);

return Some(Action::Skipped);
}

if let Some(dependency) = self.find_skipped_dependency(applied_resources) {
log::warn!(
"`{}`: skipping resource as dependency `{}` has been skipped",
self.repr(),
dependency.repr()
);

return Some(Action::Skipped);
}

None
}
}

impl Execute {
Expand Down
10 changes: 5 additions & 5 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ impl FromStr for Action {
match s {
"unchanged" => Ok(Self::Unchanged),
"created" => Ok(Self::Created),
"Changed" => Ok(Self::Changed),
"Deleted" => Ok(Self::Deleted),
"Skipped" => Ok(Self::Skipped),
"Failed" => Ok(Self::Failed),
_ => anyhow::bail!("invalid `action` value: {}", s),
"changed" => Ok(Self::Changed),
"deleted" => Ok(Self::Deleted),
"skipped" => Ok(Self::Skipped),
"failed" => Ok(Self::Failed),
_ => anyhow::bail!("value is not a valid state: `{}`", s),
}
}
}

0 comments on commit 121f6d8

Please sign in to comment.