Skip to content

Commit c1b2ff1

Browse files
committed
feat: added queueing into nats as an manual option
1 parent ddbc240 commit c1b2ff1

1 file changed

Lines changed: 57 additions & 2 deletions

File tree

crates/taurus-manual/src/main.rs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use std::path::Path;
22

3-
use clap::{Parser, arg, command};
3+
use clap::Parser;
44
use log::error;
55
use log::info;
6+
use prost::Message;
67
use serde::Deserialize;
7-
use taurus_core::runtime::engine::ExecutionEngine;
8+
use taurus_core::runtime::engine::{ExecutionEngine, ExecutionId};
89
use taurus_core::types::signal::Signal;
910
use taurus_provider::providers::emitter::nats_emitter::NATSRespondEmitter;
1011
use taurus_provider::providers::remote::nats_remote_runtime::NATSRemoteRuntime;
12+
use tucana::shared::ExecutionFlow;
1113
use tucana::shared::ValidationFlow;
1214
use tucana::shared::helper::value::from_json_value;
1315
use tucana::shared::helper::value::to_json_value;
@@ -128,6 +130,10 @@ struct Args {
128130
/// Path value
129131
#[arg(short, long)]
130132
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,
131137
}
132138

133139
#[tokio::main]
@@ -159,6 +165,12 @@ async fn main() {
159165
panic!("Failed to connect to NATS server: {}", err);
160166
}
161167
};
168+
169+
if args.queue_execution {
170+
queue_execution(&client, &case, flow_input).await;
171+
return;
172+
}
173+
162174
let remote = NATSRemoteRuntime::new(client.clone());
163175
let emitter = NATSRespondEmitter::new(client);
164176
let engine = ExecutionEngine::new();
@@ -194,3 +206,46 @@ async fn main() {
194206
}
195207
}
196208
}
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

Comments
 (0)