-
Notifications
You must be signed in to change notification settings - Fork 0
Manual Execution #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
raphael-goetz
merged 8 commits into
#96-distinguish-local-remote-execution
from
#138-manual-exec
Apr 5, 2026
Merged
Manual Execution #139
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5f7770c
ref: moved flows into root folder
raphael-goetz 19ef01f
feat: added test-core and manual crate
raphael-goetz 0c678fb
feat: made empty defintion source take runtime by default
raphael-goetz 61356ff
feat: init manual create
raphael-goetz 78f94cf
ref: split test crate into tests-core
raphael-goetz 11dc13d
feat: added remote execution & output logic
raphael-goetz bf66f71
Update crates/tests/src/main.rs
raphael-goetz 8210773
Update crates/manual/src/main.rs
raphael-goetz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,18 @@ | ||
| [package] | ||
| name = "manual" | ||
| version.workspace = true | ||
| edition.workspace = true | ||
|
|
||
| [dependencies] | ||
| tests-core = { workspace = true } | ||
| tucana = { workspace = true } | ||
| taurus-core = { workspace = true } | ||
| log = { workspace = true } | ||
| env_logger = { workspace = true } | ||
| serde_json = { workspace = true } | ||
| serde = { workspace = true } | ||
| prost = { workspace = true } | ||
| tonic = { workspace = true } | ||
| tokio = { workspace = true } | ||
| async-nats = { workspace = true } | ||
| clap ={ version = "4.6.0", features= ["derive"] } |
This file contains hidden or 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,160 @@ | ||
| use std::collections::HashMap; | ||
|
|
||
| use async_nats::Client; | ||
| use clap::{Parser, arg, command}; | ||
| use prost::Message; | ||
| use taurus_core::context::{context::Context, executor::Executor, registry::FunctionStore}; | ||
| use taurus_core::runtime::{error::RuntimeError, remote::RemoteRuntime}; | ||
| use tests_core::Case; | ||
| use tonic::async_trait; | ||
| use tucana::shared::helper::value::to_json_value; | ||
| use tucana::shared::{NodeFunction, helper::value::from_json_value}; | ||
| use tucana::{ | ||
| aquila::{ExecutionRequest, ExecutionResult}, | ||
| shared::Value, | ||
| }; | ||
|
|
||
| pub struct RemoteNatsClient { | ||
| client: Client, | ||
| } | ||
|
|
||
| impl RemoteNatsClient { | ||
| pub fn new(client: Client) -> Self { | ||
| RemoteNatsClient { client } | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl RemoteRuntime for RemoteNatsClient { | ||
| async fn execute_remote( | ||
| &self, | ||
| remote_name: String, | ||
| request: ExecutionRequest, | ||
| ) -> Result<Value, RuntimeError> { | ||
| let topic = format!("action.{}.{}", remote_name, request.execution_identifier); | ||
| let payload = request.encode_to_vec(); | ||
| let res = self.client.request(topic, payload.into()).await; | ||
| let message = match res { | ||
| Ok(r) => r, | ||
| Err(_) => { | ||
| return Err(RuntimeError::simple_str( | ||
| "RemoteRuntimeExeption", | ||
| "Failed to handle NATS message", | ||
| )); | ||
| } | ||
raphael-goetz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| let decode_result = ExecutionResult::decode(message.payload); | ||
| let execution_result = match decode_result { | ||
| Ok(r) => r, | ||
| Err(_) => { | ||
| return Err(RuntimeError::simple_str( | ||
| "RemoteRuntimeExeption", | ||
| "Failed to decode NATS message", | ||
| )); | ||
| } | ||
| }; | ||
|
|
||
| match execution_result.result { | ||
| Some(result) => match result { | ||
| tucana::aquila::execution_result::Result::Success(value) => Ok(value), | ||
| tucana::aquila::execution_result::Result::Error(err) => { | ||
| let name = err.code.to_string(); | ||
| let description = match err.description { | ||
| Some(string) => string, | ||
| None => "Unknown Error".to_string(), | ||
| }; | ||
| let error = RuntimeError::new(name, description, None); | ||
| Err(error) | ||
| } | ||
| }, | ||
| None => Err(RuntimeError::simple_str( | ||
| "RemoteRuntimeExeption", | ||
| "Result of Remote Response was empty.", | ||
| )), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(clap::Parser, Debug)] | ||
| #[command(author, version, about)] | ||
| struct Args { | ||
| /// Index value | ||
| #[arg(short, long, default_value_t = 0)] | ||
| index: i32, | ||
|
|
||
| /// NATS server URL | ||
| #[arg(short, long, default_value_t = String::from("nats://127.0.0.1:4222"))] | ||
| nats_url: String, | ||
|
|
||
| /// Path value | ||
| #[arg(short, long)] | ||
| path: String, | ||
| } | ||
|
|
||
| #[tokio::main] | ||
| async fn main() { | ||
| env_logger::Builder::from_default_env() | ||
| .filter_level(log::LevelFilter::Info) | ||
| .init(); | ||
|
|
||
| let args = Args::parse(); | ||
| let index = args.index; | ||
| let nats_url = args.nats_url; | ||
| let path = args.path; | ||
| let case = Case::from_path(&path); | ||
|
|
||
| let store = FunctionStore::default(); | ||
|
|
||
| let node_functions: HashMap<i64, NodeFunction> = case | ||
| .clone() | ||
| .flow | ||
| .node_functions | ||
| .into_iter() | ||
| .map(|node| (node.database_id, node)) | ||
| .collect(); | ||
|
|
||
| let mut context = match case.inputs.get(index as usize) { | ||
| Some(inp) => match inp.input.clone() { | ||
| Some(json_input) => Context::new(from_json_value(json_input)), | ||
| None => Context::default(), | ||
| }, | ||
raphael-goetz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| None => Context::default(), | ||
| }; | ||
|
|
||
| let client = match async_nats::connect(nats_url).await { | ||
| Ok(client) => { | ||
| log::info!("Connected to nats server"); | ||
| client | ||
| } | ||
| Err(err) => { | ||
| panic!("Failed to connect to NATS server: {}", err); | ||
| } | ||
| }; | ||
| let remote = RemoteNatsClient::new(client); | ||
| let result = Executor::new(&store, node_functions.clone()) | ||
| .with_remote_runtime(&remote) | ||
| .execute(case.flow.starting_node_id, &mut context, true); | ||
|
|
||
| match result { | ||
| taurus_core::context::signal::Signal::Success(value) => { | ||
| let json = to_json_value(value); | ||
| let pretty = serde_json::to_string_pretty(&json).unwrap(); | ||
| println!("{}", pretty); | ||
| } | ||
| taurus_core::context::signal::Signal::Return(value) => { | ||
| let json = to_json_value(value); | ||
| let pretty = serde_json::to_string_pretty(&json).unwrap(); | ||
| println!("{}", pretty); | ||
| } | ||
| taurus_core::context::signal::Signal::Respond(value) => { | ||
| let json = to_json_value(value); | ||
| let pretty = serde_json::to_string_pretty(&json).unwrap(); | ||
| println!("{}", pretty); | ||
| } | ||
| taurus_core::context::signal::Signal::Stop => println!("Received Stop signal"), | ||
| taurus_core::context::signal::Signal::Failure(runtime_error) => { | ||
| println!("RuntimeError: {:?}", runtime_error); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,13 @@ | ||
| [package] | ||
| name = "tests-core" | ||
| version.workspace = true | ||
| edition.workspace = true | ||
|
|
||
| [dependencies] | ||
| tucana = { workspace = true } | ||
| taurus-core = { workspace = true } | ||
| log = { workspace = true } | ||
| env_logger = { workspace = true } | ||
| serde_json = { workspace = true } | ||
| serde = { workspace = true } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.