-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2912 from didier-wenzek/refactor/rename-workflow-…
…actor refactoring: rename workflow related structs
- Loading branch information
Showing
9 changed files
with
89 additions
and
82 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
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
File renamed without changes.
File renamed without changes.
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,62 @@ | ||
use anyhow::Context; | ||
use camino::Utf8PathBuf; | ||
use log::error; | ||
use std::ffi::OsStr; | ||
use std::path::Path; | ||
use tedge_api::workflow::OperationWorkflow; | ||
use tedge_api::workflow::WorkflowSupervisor; | ||
use tracing::info; | ||
|
||
mod actor; | ||
mod builder; | ||
mod config; | ||
mod message_box; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
pub use builder::WorkflowActorBuilder; | ||
pub use config::OperationConfig; | ||
|
||
pub async fn load_operation_workflows( | ||
dir_path: &Utf8PathBuf, | ||
) -> Result<WorkflowSupervisor, anyhow::Error> { | ||
let mut workflows = WorkflowSupervisor::default(); | ||
for entry in std::fs::read_dir(dir_path)?.flatten() { | ||
let file = entry.path(); | ||
if file.extension() == Some(OsStr::new("toml")) { | ||
match read_operation_workflow(&file) | ||
.await | ||
.and_then(|workflow| load_operation_workflow(&mut workflows, workflow)) | ||
{ | ||
Ok(cmd) => { | ||
info!( | ||
"Using operation workflow definition from {file:?} for '{cmd}' operation" | ||
); | ||
} | ||
Err(err) => { | ||
error!("Ignoring operation workflow definition from {file:?}: {err:?}") | ||
} | ||
}; | ||
} | ||
} | ||
Ok(workflows) | ||
} | ||
|
||
async fn read_operation_workflow(path: &Path) -> Result<OperationWorkflow, anyhow::Error> { | ||
let bytes = tokio::fs::read(path) | ||
.await | ||
.context("Reading file content")?; | ||
let input = std::str::from_utf8(&bytes).context("Expecting UTF8 content")?; | ||
let workflow = toml::from_str::<OperationWorkflow>(input).context("Parsing TOML content")?; | ||
Ok(workflow) | ||
} | ||
|
||
fn load_operation_workflow( | ||
workflows: &mut WorkflowSupervisor, | ||
workflow: OperationWorkflow, | ||
) -> Result<String, anyhow::Error> { | ||
let name = workflow.operation.to_string(); | ||
workflows.register_custom_workflow(workflow)?; | ||
Ok(name) | ||
} |
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 was deleted.
Oops, something went wrong.