Skip to content
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

constants: change static keyword to const . #20

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
132 changes: 132 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ After completing the flow design in Node-RED, please ensure that you click the b

### 1. Build

Using Rust 1.80 or later, run:

```bash
cargo build -r
```
Expand Down Expand Up @@ -99,7 +101,8 @@ py.test

## Configuration

Adjust various settings in the configuration file, such as port number, `flows.json` path, etc. Refer to [CONFIG.md](docs/CONFIG.md) for more information.
Adjust various settings and configuration, please execute `edgelinkd` with flags.
The flags available can be found when executing `edgelinkd --help`.

## Project Status

Expand Down
2 changes: 2 additions & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ smallvec.workspace = true
smallstr.workspace = true
inventory.workspace = true
arrayvec = { workspace = true, features = ["std", "serde"] }
validator = { version = "0.18.1", features = ["derive"] }


[dev-dependencies]
# Enable test-utilities in dev mode only. This is mostly for tests.
Expand Down
10 changes: 8 additions & 2 deletions crates/core/src/runtime/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use super::nodes::FlowNodeBehavior;
use crate::runtime::model::Variant;
use crate::runtime::nodes::{GlobalNodeBehavior, NodeFactory};
use crate::*;
use crate::utils::constants::SUB_FLOW_TYPE;

#[derive(Debug, Clone, Deserialize, Default)]
pub struct EngineArgs {
Expand Down Expand Up @@ -161,7 +162,12 @@ impl Engine {
) -> crate::Result<()> {
// load flows
for flow_config in flow_cfg.into_iter() {
log::debug!("---- Loading flow/subflow: (id='{}', label='{}')...", flow_config.id, flow_config.label);
if &flow_config.type_name==SUB_FLOW_TYPE {
log::debug!("---- Loading subflow: (id='{}', label='{}')...", flow_config.id, flow_config.label);
}else{
log::debug!("---- Loading flow: (id='{}', label='{}')...", flow_config.id, flow_config.label);
}

let flow = Flow::new(self, flow_config, reg, elcfg)?;
{
// register all nodes
Expand All @@ -171,7 +177,7 @@ impl Engine {
"This flow node already existed: {}",
fnode
))
.into());
.into());
}
self.inner.all_flow_nodes.insert(fnode.id(), fnode.clone());
}
Expand Down
33 changes: 21 additions & 12 deletions crates/core/src/runtime/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use crate::runtime::model::json::*;
use crate::runtime::model::*;
use crate::runtime::nodes::*;
use crate::runtime::registry::Registry;
use crate::EdgelinkError;
use crate::{EdgelinkError, handle_option};
use crate::utils::constants::{ENV_STR, FLOW_STR, SUB_FLOW_TYPE, SUB_FLOW_TYPE_HEAD, TAB_STR};

const NODE_MSG_CHANNEL_CAPACITY: usize = 32;

Expand Down Expand Up @@ -71,6 +72,17 @@ pub enum FlowKind {
Subflow,
}

impl FlowKind {
pub fn from(value: &str) -> Option<Self> {
if value == SUB_FLOW_TYPE {
return Some(FlowKind::Subflow);
}else if value == TAB_STR {
return Some(FlowKind::GlobalFlow);
}
None
}
}

#[derive(Debug)]
struct InnerFlow {
id: ElementId,
Expand Down Expand Up @@ -185,11 +197,8 @@ impl Flow {
reg: &RegistryHandle,
options: Option<&config::Config>,
) -> crate::Result<Flow> {
let flow_kind = match flow_config.type_name.as_str() {
"tab" => FlowKind::GlobalFlow,
"subflow" => FlowKind::Subflow,
_ => return Err(EdgelinkError::BadFlowsJson("Unsupported flow type".to_string()).into()),
};

let flow_kind = handle_option!(result: FlowKind::from(&flow_config.type_name),EdgelinkError::BadFlowsJson,str:"Unsupported flow type");

let subflow_instance = flow_config.subflow_node_id.and_then(|x| engine.find_flow_node_by_id(&x));

Expand All @@ -205,7 +214,7 @@ impl Flow {
}
}
};
if let Some(env_json) = flow_config.rest.get("env") {
if let Some(env_json) = flow_config.rest.get(ENV_STR) {
envs_builder = envs_builder.load_json(env_json);
}
if let Some(ref instance) = subflow_instance {
Expand Down Expand Up @@ -249,8 +258,8 @@ impl Flow {
ordering: flow_config.ordering,
_args: args.clone(),
type_str: match flow_kind {
FlowKind::GlobalFlow => "flow",
FlowKind::Subflow => "subflow",
FlowKind::GlobalFlow => FLOW_STR,
FlowKind::Subflow => SUB_FLOW_TYPE,
},
groups: DashMap::new(),
nodes: DashMap::new(),
Expand Down Expand Up @@ -309,8 +318,8 @@ impl Flow {
for node_config in flow_config.nodes.iter() {
let meta_node = if let Some(meta_node) = reg.get(&node_config.type_name) {
meta_node
} else if node_config.type_name.starts_with("subflow:") {
reg.get("subflow").expect("The `subflow` node must be existed")
} else if node_config.type_name.starts_with(SUB_FLOW_TYPE_HEAD) {
reg.get(SUB_FLOW_TYPE).expect("The `subflow` node must be existed")
} else {
log::warn!(
"Unknown flow node type: (type='{}', id='{}', name='{}')",
Expand Down Expand Up @@ -637,7 +646,7 @@ impl Flow {
} else {
envs_builder = envs_builder.with_parent(self.get_envs());
}
if let Some(env_json) = node_config.rest.get("env") {
if let Some(env_json) = node_config.rest.get(ENV_STR) {
envs_builder = envs_builder.load_json(env_json);
}
let envs = envs_builder
Expand Down
3 changes: 2 additions & 1 deletion crates/core/src/runtime/group.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;
use std::sync::Weak;
use crate::utils::constants::ENV_STR;

use super::env::*;
use super::flow::*;
Expand Down Expand Up @@ -119,7 +120,7 @@ impl Group {
}

fn build_envs(mut envs_builder: EnvStoreBuilder, config: &RedGroupConfig) -> Envs {
if let Some(env_json) = config.rest.get("env") {
if let Some(env_json) = config.rest.get(ENV_STR) {
envs_builder = envs_builder.load_json(env_json);
}
envs_builder
Expand Down
Loading