Skip to content

Commit

Permalink
fixup! Improve struct WorkflowSource
Browse files Browse the repository at this point in the history
Simply use bool instead of WorkflowSource<()> which usage was not really clear.

Signed-off-by: Didier Wenzek <[email protected]>
  • Loading branch information
didier-wenzek committed Oct 22, 2024
1 parent 840e139 commit e9ec57a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions crates/core/tedge_agent/src/operation_workflows/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ impl WorkflowRepository {
.find(|(_, (_, p))| p == removed_path)
.map(|(n, (v, _))| (n.clone(), v.clone()))?;
self.definitions.remove(&operation);
let deprecated = self
let builtin_restored = self
.workflows
.unregister_custom_workflow(&operation, &removed_version);
if matches!(deprecated, Some(WorkflowSource::BuiltIn)) {
if builtin_restored {
info!("The builtin workflow for the '{operation}' operation has been restored");
None
} else {
Expand Down
20 changes: 9 additions & 11 deletions crates/core/tedge_api/src/workflow/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,29 @@ impl WorkflowSupervisor {

/// Un-register a user-defined workflow
///
/// Return None is this was the last version for that operation.
/// Return Some(BuiltIn) is there is a builtin definition
/// Return Some(InUseCopy) if the workflow has been deprecated but there is still a running command.
/// Return true if a builtin version has been restored
pub fn unregister_custom_workflow(
&mut self,
operation: &OperationName,
version: &WorkflowVersion,
) -> Option<WorkflowSource<()>> {
) -> bool {
let operation = OperationType::from(operation.as_str());
if let Some(versions) = self.workflows.get_mut(&operation) {
versions.remove(version);
}

let current_source = match self.workflows.get(&operation) {
None => None,
Some(version) if version.is_empty() => None,
Some(version) if version.is_builtin() => Some(BuiltIn),
Some(_) => Some(InUseCopy(())),
let (empty,builtin_restored) = match self.workflows.get(&operation) {
None => (true, false),
Some(version) if version.is_empty() => (true, false),
Some(version) if version.is_builtin() => (false, true),
Some(_) => (false, false),
};

if current_source.is_none() {
if empty {
self.workflows.remove(&operation);
}

current_source
builtin_restored
}

/// The set of pending commands
Expand Down

0 comments on commit e9ec57a

Please sign in to comment.