Skip to content

Commit 150103f

Browse files
committed
feat: used new core crate
1 parent 3589043 commit 150103f

3 files changed

Lines changed: 40 additions & 80 deletions

File tree

crates/taurus/src/config/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
use code0_flow::flow_config::env_with_default;
2-
use code0_flow::flow_config::environment::Environment;
32
use code0_flow::flow_config::mode::Mode;
43

54
/// Struct for all relevant `Taurus` startup configurations
65
pub struct Config {
7-
/// Options:
8-
/// `development` (default)
9-
/// `staging`
10-
/// `production`
11-
pub environment: Environment,
12-
136
/// Aquila mode
147
///
158
/// Options:
@@ -39,7 +32,6 @@ pub struct Config {
3932
impl Config {
4033
pub fn new() -> Self {
4134
Config {
42-
environment: env_with_default("ENVIRONMENT", Environment::Development),
4335
mode: env_with_default("MODE", Mode::DYNAMIC),
4436
nats_url: env_with_default("NATS_URL", String::from("nats://localhost:4222")),
4537
aquila_url: env_with_default("AQUILA_URL", String::from("http://localhost:50051")),

crates/taurus/src/main.rs

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -13,71 +13,33 @@ use code0_flow::flow_config::mode::Mode::DYNAMIC;
1313
use futures_lite::StreamExt;
1414
use log::error;
1515
use prost::Message;
16-
use std::collections::HashMap;
1716
use std::sync::Arc;
1817
use std::sync::atomic::{AtomicUsize, Ordering};
1918
use std::time::{Duration, Instant};
20-
use taurus_core::context::context::Context;
21-
use taurus_core::context::executor::Executor;
22-
use taurus_core::context::registry::FunctionStore;
23-
use taurus_core::context::signal::Signal;
24-
use taurus_core::runtime::error::RuntimeError;
19+
use taurus_core::runtime::engine::{EmitType, ExecutionEngine, RespondEmitter};
20+
use taurus_core::types::signal::Signal;
2521
use tokio::signal;
2622
use tokio::sync::mpsc;
2723
use tokio::time::sleep;
2824
use tonic_health::pb::health_server::HealthServer;
2925
use tucana::shared::value::Kind;
30-
use tucana::shared::{
31-
ExecutionFlow, NodeFunction, RuntimeFeature, RuntimeUsage, Translation, Value,
32-
};
26+
use tucana::shared::{ExecutionFlow, RuntimeFeature, RuntimeUsage, Translation, Value};
3327

3428
fn handle_message(
3529
flow: ExecutionFlow,
36-
store: &FunctionStore,
30+
engine: &ExecutionEngine,
3731
nats_remote: &RemoteNatsClient,
38-
respond_emitter: Option<&dyn Fn(Value)>,
32+
respond_emitter: Option<&dyn RespondEmitter>,
3933
) -> (Signal, RuntimeUsage) {
4034
let start = Instant::now();
41-
let mut context = match flow.input_value {
42-
Some(v) => {
43-
log::debug!("Input Value for flow: {:?}", v);
44-
Context::new(v)
45-
}
46-
None => Context::default(),
47-
};
48-
49-
if flow.node_functions.is_empty() {
50-
let duration_millis = start.elapsed().as_millis() as i64;
51-
return (
52-
Signal::Failure(RuntimeError::simple_str(
53-
"InvalidFlow",
54-
"This flow has no nodes to execute!",
55-
)),
56-
RuntimeUsage {
57-
flow_id: flow.flow_id,
58-
duration: duration_millis,
59-
},
60-
);
61-
}
62-
63-
let node_functions: HashMap<i64, NodeFunction> = flow
64-
.node_functions
65-
.into_iter()
66-
.map(|node| (node.database_id, node))
67-
.collect();
68-
69-
let mut executor = Executor::new(store, node_functions).with_remote_runtime(nats_remote);
70-
if let Some(emitter) = respond_emitter {
71-
executor = executor.with_respond_emitter(emitter);
72-
}
73-
74-
let signal = executor.execute(flow.starting_node_id, &mut context, true);
35+
let flow_id = flow.flow_id;
36+
let (signal, _reason) = engine.execute_flow(flow, Some(nats_remote), respond_emitter, true);
7537
let duration_millis = start.elapsed().as_millis() as i64;
7638

7739
(
7840
signal,
7941
RuntimeUsage {
80-
flow_id: flow.flow_id,
42+
flow_id,
8143
duration: duration_millis,
8244
},
8345
)
@@ -92,7 +54,7 @@ async fn main() {
9254
load_env_file();
9355

9456
let config = Config::new();
95-
let store = FunctionStore::default();
57+
let engine = ExecutionEngine::new();
9658
let mut runtime_status_service: Option<TaurusRuntimeStatusService> = None;
9759
let mut runtime_usage_service: Option<TaurusRuntimeUsageService> = None;
9860

@@ -240,18 +202,23 @@ async fn main() {
240202
let emit_tx = respond_tx.clone();
241203
let respond_count = Arc::new(AtomicUsize::new(0));
242204
let respond_count_for_emitter = respond_count.clone();
243-
let respond_emitter = move |value: Value| {
244-
respond_count_for_emitter.fetch_add(1, Ordering::Relaxed);
245-
if let Err(err) = emit_tx.send(value) {
246-
log::debug!(
247-
"Dropped respond signal value because publisher is unavailable: {:?}",
248-
err
249-
);
205+
let respond_emitter = move |emit_type: EmitType, value: Value| match emit_type {
206+
EmitType::OngoingExec => {
207+
respond_count_for_emitter.fetch_add(1, Ordering::Relaxed);
208+
if let Err(err) = emit_tx.send(value) {
209+
log::debug!(
210+
"Dropped respond signal value because publisher is unavailable: {:?}",
211+
err
212+
);
213+
}
250214
}
215+
EmitType::StartingExec => log::debug!("Flow execution started"),
216+
EmitType::FinishedExec => log::debug!("Flow execution finished"),
217+
EmitType::FailedExec => log::debug!("Flow execution failed"),
251218
};
252219

253220
let (signal, runtime_usage) =
254-
handle_message(flow, &store, &nats_client, Some(&respond_emitter));
221+
handle_message(flow, &engine, &nats_client, Some(&respond_emitter));
255222
drop(respond_emitter);
256223
drop(respond_tx);
257224

crates/taurus/src/remote/mod.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use async_nats::Client;
22
use prost::Message;
3-
use taurus_core::runtime::{error::RuntimeError, remote::RemoteRuntime};
3+
use taurus_core::runtime::remote::{RemoteExecution, RemoteRuntime};
4+
use taurus_core::types::errors::runtime_error::RuntimeError;
45
use tonic::async_trait;
5-
use tucana::{
6-
aquila::{ExecutionRequest, ExecutionResult},
7-
shared::Value,
8-
};
6+
use tucana::aquila::ExecutionResult;
7+
use tucana::shared::Value;
98

109
pub struct RemoteNatsClient {
1110
client: Client,
@@ -19,13 +18,12 @@ impl RemoteNatsClient {
1918

2019
#[async_trait]
2120
impl RemoteRuntime for RemoteNatsClient {
22-
async fn execute_remote(
23-
&self,
24-
remote_name: String,
25-
request: ExecutionRequest,
26-
) -> Result<Value, RuntimeError> {
27-
let topic = format!("action.{}.{}", remote_name, request.execution_identifier);
28-
let payload = request.encode_to_vec();
21+
async fn execute_remote(&self, execution: RemoteExecution) -> Result<Value, RuntimeError> {
22+
let topic = format!(
23+
"action.{}.{}",
24+
execution.target_service, execution.request.execution_identifier
25+
);
26+
let payload = execution.request.encode_to_vec();
2927
log::info!("Publishing to topic: {}", topic);
3028
let res = self.client.request(topic, payload.into()).await;
3129
let message = match res {
@@ -35,7 +33,8 @@ impl RemoteRuntime for RemoteNatsClient {
3533
"RemoteRuntimeExeption: failed to handle NATS message: {}",
3634
err
3735
);
38-
return Err(RuntimeError::simple_str(
36+
return Err(RuntimeError::new(
37+
"T-RMT-000001",
3938
"RemoteRuntimeExeption",
4039
"Failed to receive any response messages from a remote runtime.",
4140
));
@@ -50,7 +49,8 @@ impl RemoteRuntime for RemoteNatsClient {
5049
"RemoteRuntimeExeption: failed to decode NATS message: {}",
5150
err
5251
);
53-
return Err(RuntimeError::simple_str(
52+
return Err(RuntimeError::new(
53+
"T-RMT-000002",
5454
"RemoteRuntimeExeption",
5555
"Failed to read Remote Response",
5656
));
@@ -61,16 +61,17 @@ impl RemoteRuntime for RemoteNatsClient {
6161
Some(result) => match result {
6262
tucana::aquila::execution_result::Result::Success(value) => Ok(value),
6363
tucana::aquila::execution_result::Result::Error(err) => {
64-
let name = err.code.to_string();
64+
let code = err.code.to_string();
6565
let description = match err.description {
6666
Some(string) => string,
6767
None => "Unknown Error".to_string(),
6868
};
69-
let error = RuntimeError::new(name, description, None);
69+
let error = RuntimeError::new(code, "RemoteExecutionError", description);
7070
Err(error)
7171
}
7272
},
73-
None => Err(RuntimeError::simple_str(
73+
None => Err(RuntimeError::new(
74+
"T-RMT-000003",
7475
"RemoteRuntimeExeption",
7576
"Result of Remote Response was empty.",
7677
)),

0 commit comments

Comments
 (0)