|
1 | 1 | use std::path::Path; |
2 | 2 |
|
3 | | -use clap::{Parser, arg, command}; |
| 3 | +use clap::Parser; |
4 | 4 | use log::error; |
5 | 5 | use log::info; |
| 6 | +use prost::Message; |
6 | 7 | use serde::Deserialize; |
7 | | -use taurus_core::runtime::engine::ExecutionEngine; |
| 8 | +use taurus_core::runtime::engine::{ExecutionEngine, ExecutionId}; |
8 | 9 | use taurus_core::types::signal::Signal; |
9 | 10 | use taurus_provider::providers::emitter::nats_emitter::NATSRespondEmitter; |
10 | 11 | use taurus_provider::providers::remote::nats_remote_runtime::NATSRemoteRuntime; |
| 12 | +use tucana::shared::ExecutionFlow; |
11 | 13 | use tucana::shared::ValidationFlow; |
12 | 14 | use tucana::shared::helper::value::from_json_value; |
13 | 15 | use tucana::shared::helper::value::to_json_value; |
@@ -128,6 +130,10 @@ struct Args { |
128 | 130 | /// Path value |
129 | 131 | #[arg(short, long)] |
130 | 132 | path: String, |
| 133 | + |
| 134 | + /// Queue the selected flow on a running Taurus instance instead of executing locally |
| 135 | + #[arg(long, default_value_t = false)] |
| 136 | + queue_execution: bool, |
131 | 137 | } |
132 | 138 |
|
133 | 139 | #[tokio::main] |
@@ -159,6 +165,12 @@ async fn main() { |
159 | 165 | panic!("Failed to connect to NATS server: {}", err); |
160 | 166 | } |
161 | 167 | }; |
| 168 | + |
| 169 | + if args.queue_execution { |
| 170 | + queue_execution(&client, &case, flow_input).await; |
| 171 | + return; |
| 172 | + } |
| 173 | + |
162 | 174 | let remote = NATSRemoteRuntime::new(client.clone()); |
163 | 175 | let emitter = NATSRespondEmitter::new(client); |
164 | 176 | let engine = ExecutionEngine::new(); |
@@ -194,3 +206,46 @@ async fn main() { |
194 | 206 | } |
195 | 207 | } |
196 | 208 | } |
| 209 | + |
| 210 | +async fn queue_execution( |
| 211 | + client: &async_nats::Client, |
| 212 | + case: &Case, |
| 213 | + input_value: Option<tucana::shared::Value>, |
| 214 | +) { |
| 215 | + let execution_id = ExecutionId::new_v4(); |
| 216 | + let execution_flow = ExecutionFlow { |
| 217 | + flow_id: case.flow.flow_id, |
| 218 | + project_id: case.flow.project_id, |
| 219 | + starting_node_id: case.flow.starting_node_id, |
| 220 | + node_functions: case.flow.node_functions.clone(), |
| 221 | + input_value, |
| 222 | + }; |
| 223 | + let execution_topic = format!("execution.{}", execution_id); |
| 224 | + |
| 225 | + info!( |
| 226 | + "Queueing execution of flow {} with execution id {}", |
| 227 | + execution_flow.flow_id, execution_id |
| 228 | + ); |
| 229 | + |
| 230 | + if let Err(err) = client |
| 231 | + .publish( |
| 232 | + execution_topic.clone(), |
| 233 | + execution_flow.encode_to_vec().into(), |
| 234 | + ) |
| 235 | + .await |
| 236 | + { |
| 237 | + panic!( |
| 238 | + "Failed to publish flow {} to execution topic '{}': {}", |
| 239 | + case.flow.flow_id, execution_topic, err |
| 240 | + ); |
| 241 | + } |
| 242 | + |
| 243 | + if let Err(err) = client.flush().await { |
| 244 | + panic!( |
| 245 | + "Failed to flush execution request on '{}': {}", |
| 246 | + execution_topic, err |
| 247 | + ); |
| 248 | + } |
| 249 | + |
| 250 | + println!("{}", execution_id); |
| 251 | +} |
0 commit comments