Add cluster plugin skeleton

This commit is contained in:
ppom 2025-10-20 12:00:00 +02:00
commit 61fe405b85
No known key found for this signature in database
6 changed files with 161 additions and 1 deletions

9
Cargo.lock generated
View file

@ -1071,6 +1071,15 @@ dependencies = [
"tokio",
]
[[package]]
name = "reaction-plugin-cluster"
version = "0.1.0"
dependencies = [
"reaction-plugin",
"remoc",
"tokio",
]
[[package]]
name = "reaction-plugin-virtual"
version = "0.1.0"

View file

@ -75,7 +75,7 @@ assert_cmd = "2.0.17"
predicates = "3.1.3"
[workspace]
members = ["plugins/reaction-plugin", "plugins/reaction-plugin-virtual"]
members = ["plugins/reaction-plugin", "plugins/reaction-plugin-cluster", "plugins/reaction-plugin-virtual"]
[workspace.dependencies]
remoc = { version = "0.18.3" }

12
TODO
View file

@ -2,3 +2,15 @@ Test what happens when a Filter's pattern Set changes (I think it's shitty)
DB: add tests on stress testing (lines should always be in order)
plugins: pipe stderr too and wrap errors in logs
plugins: provide tree storage? omg
questionnements:
- quelle cli pour les plugins ?
- Directement en appelant le plugin ? reaction-plugin-cluster gen-id ? 🟢
→ Demande de savoir où stocker tout ça
- Via moult IPC ? reaction plugin cluster gen-id ? 🔴
→ Mais du coup c'est l'oeuf ou la poule entre avoir un serveur qui fonctionne et avoir un
- Stockage ?
- uniquement dans la db reaction
→ Faut pas que ce soit trop gros, un peu d'overhead, risque de perdre la donnée
- à part dans le configuration directory
→ Pas mal en vrai

View file

@ -0,0 +1,9 @@
[package]
name = "reaction-plugin-cluster"
version = "0.1.0"
edition = "2024"
[dependencies]
tokio = { workspace = true, features = ["rt-multi-thread"] }
remoc.workspace = true
reaction-plugin.path = "../reaction-plugin"

View file

@ -0,0 +1,58 @@
use std::collections::BTreeSet;
use reaction_plugin::{
ActionImpl, Hello, Manifest, PersistData, PluginInfo, RemoteResult, StreamImpl, Value,
main_loop,
};
use remoc::rtc;
#[tokio::main]
async fn main() {
let plugin = Plugin::default();
main_loop(plugin).await;
}
#[derive(Default)]
struct Plugin {
data: Option<PersistData>,
}
impl PluginInfo for Plugin {
async fn manifest(&mut self, data: PersistData) -> Result<Manifest, rtc::CallError> {
self.data = Some(data);
Ok(Manifest {
hello: Hello::hello(),
streams: BTreeSet::from(["cluster".into()]),
actions: BTreeSet::from(["cluster_send".into()]),
})
}
async fn stream_impl(
&mut self,
stream_name: String,
stream_type: String,
config: Value,
) -> RemoteResult<StreamImpl> {
todo!()
}
async fn action_impl(
&mut self,
stream_name: String,
filter_name: String,
action_name: String,
action_type: String,
config: Value,
patterns: Vec<String>,
) -> RemoteResult<ActionImpl> {
todo!()
}
async fn finish_setup(&mut self) -> RemoteResult<()> {
todo!()
}
async fn close(self) -> RemoteResult<()> {
todo!()
}
}

View file

@ -0,0 +1,72 @@
{
patterns: {
num: {
regex: @"[0-9]+",
},
all: {
regex: @".*",
},
},
plugins: {
cluster: {
path: "./target/debug/reaction-plugin-cluster",
check_root: false,
systemd_options: {
DynamicUser: ["false"],
},
options: {
clusters: {
org1: {
listen_port: 9000,
bootstrap_nodes: {
"public_key": ["127.0.0.1:9001"],
},
},
},
},
},
},
streams: {
s0: {
cmd: ["bash", "-c", "for i in $(seq 4); do echo $i; sleep 0.1; done; sleep 1.2"],
filters: {
f0: {
regex: ["^<num>$"],
actions: {
a0: {
type: "virtual",
options: {
send: "a0 <num>",
to: "s1",
}
},
b0: {
type: "virtual",
options: {
send: "b0 <num>",
to: "s1",
},
after: "600ms",
},
},
},
},
},
s1: {
type: "cluster",
options: {},
filters: {
f1: {
regex: ["^<all>$"],
actions: {
a1: {
cmd: ['sh', '-c', 'echo <all> >>./log'],
},
},
},
},
},
},
}