mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-12-25 21:23:49 +01:00
Re-enable MQTT
This commit is contained in:
parent
73f63238a8
commit
ba73fe80c5
@ -1,14 +1,14 @@
|
||||
-- { actor_connections = [] : List { _1 : Text, _2 : Text }
|
||||
{ actor_connections =
|
||||
-- Link up machines to actors
|
||||
[ { _1 = "Testmachine", _2 = "Actor" }
|
||||
[ { _1 = "Testmachine", _2 = "Shelly_1234" }
|
||||
, { _1 = "Another", _2 = "Bash" }
|
||||
-- One machine can have as many actors as it wants
|
||||
, { _1 = "Yetmore", _2 = "Bash2" }
|
||||
, { _1 = "Yetmore", _2 = "FailBash"}
|
||||
]
|
||||
, actors =
|
||||
{ Actor = { module = "Dummy", params = {=} }
|
||||
{ Shelly_1234 = { module = "Shelly", params = {=} }
|
||||
, Bash = { module = "Process", params =
|
||||
{ cmd = "./examples/actor.sh"
|
||||
, args = "your ad could be here"
|
||||
@ -23,8 +23,8 @@
|
||||
}
|
||||
, init_connections = [] : List { _1 : Text, _2 : Text }
|
||||
--, init_connections = [{ _1 = "Initiator", _2 = "Testmachine" }]
|
||||
, initiators = --{=}
|
||||
{ Initiator = { module = "Dummy", params = {=} } }
|
||||
, initiators = {=}
|
||||
--{ Initiator = { module = "Dummy", params = {=} } }
|
||||
, listens =
|
||||
[ { address = "127.0.0.1", port = Some 59661 }
|
||||
, { address = "::1", port = Some 59661 }
|
||||
@ -56,7 +56,7 @@
|
||||
, write = "lab.test.write"
|
||||
}
|
||||
}
|
||||
, mqtt_url = ""
|
||||
, mqtt_url = "tcp://localhost:1883"
|
||||
, db_path = "/tmp/bffh"
|
||||
, roles =
|
||||
{ testrole =
|
||||
|
19
src/actor.rs
19
src/actor.rs
@ -114,8 +114,8 @@ pub struct Dummy {
|
||||
}
|
||||
|
||||
impl Dummy {
|
||||
pub fn new(log: &Logger) -> Self {
|
||||
Self { log: log.new(o!("module" => "Dummy Actor")) }
|
||||
pub fn new(log: Logger) -> Self {
|
||||
Self { log }
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,8 +129,12 @@ impl Actuator for Dummy {
|
||||
pub fn load(log: &Logger, config: &Config) -> Result<(ActorMap, Vec<Actor>)> {
|
||||
let mut map = HashMap::new();
|
||||
|
||||
let mqtt = AsyncClient::new(config.mqtt_url.clone())?;
|
||||
let tok = mqtt.connect(paho_mqtt::ConnectOptions::new());
|
||||
smol::block_on(tok)?;
|
||||
|
||||
let actuators = config.actors.iter()
|
||||
.map(|(k,v)| (k, load_single(log, k, &v.module, &v.params)))
|
||||
.map(|(k,v)| (k, load_single(log, k, &v.module, &v.params, mqtt.clone())))
|
||||
.filter_map(|(k, n)| match n {
|
||||
None => None,
|
||||
Some(a) => Some((k, a))
|
||||
@ -151,20 +155,25 @@ fn load_single(
|
||||
log: &Logger,
|
||||
name: &String,
|
||||
module_name: &String,
|
||||
params: &HashMap<String, String>
|
||||
params: &HashMap<String, String>,
|
||||
client: AsyncClient,
|
||||
) -> Option<Box<dyn Actuator + Sync + Send>>
|
||||
{
|
||||
use crate::modules::*;
|
||||
|
||||
info!(log, "Loading actor \"{}\" with module {} and params {:?}", name, module_name, params);
|
||||
let log = log.new(o!("name" => name.clone()));
|
||||
match module_name.as_ref() {
|
||||
"Dummy" => {
|
||||
Some(Box::new(Dummy::new(log)))
|
||||
}
|
||||
"Process" => {
|
||||
Process::new(log.new(o!("name" => name.clone())), name.clone(), params)
|
||||
Process::new(log, name.clone(), params)
|
||||
.map(|a| a.into_boxed_actuator())
|
||||
}
|
||||
"Shelly" => {
|
||||
Some(Box::new(Shelly::new(log, name.clone(), client)))
|
||||
}
|
||||
_ => {
|
||||
error!(log, "No actor found with name \"{}\", configured as \"{}\".", module_name, name);
|
||||
None
|
||||
|
@ -167,11 +167,6 @@ fn maybe(matches: clap::ArgMatches, log: Arc<Logger>) -> Result<(), Error> {
|
||||
let ex = Executor::new();
|
||||
let db = db::Databases::new(&log, &config)?;
|
||||
|
||||
//let mqtt = AsyncClient::new(config.mqtt_url.clone())?;
|
||||
//let tok = mqtt.connect(paho_mqtt::ConnectOptions::new());
|
||||
|
||||
//smol::block_on(tok)?;
|
||||
|
||||
let machines = machine::load(&config)?;
|
||||
let (actor_map, actors) = actor::load(&log, &config)?;
|
||||
let (init_map, initiators) = initiator::load(&log, &config)?;
|
||||
|
@ -22,8 +22,7 @@ pub struct Shelly {
|
||||
}
|
||||
|
||||
impl Shelly {
|
||||
pub fn new(log_view: &Logger, name: String, client: mqtt::AsyncClient) -> Self {
|
||||
let log = log_view.new(o!("shelly_name" => name.clone()));
|
||||
pub fn new(log: Logger, name: String, client: mqtt::AsyncClient) -> Self {
|
||||
debug!(log, "Starting shelly module for {}", &name);
|
||||
Shelly { log, name, client, }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user