Host: one place for the instance config; message ids are strings

This commit is contained in:
2026-10-15 13:44:06 +01:00
parent 11144b947e
commit f9260faa5b
4 changed files with 27 additions and 42 deletions
+22 -14
View File
@@ -19,7 +19,7 @@ use wasmtime::component::Component;
use crate::candidate;
use crate::fs::Mount;
use crate::runtime::Runtime;
use crate::runtime::{InstanceConfig, Runtime};
use crate::supervisor::{Control, Reply, Supervisor};
use crate::world::{self, ActorMeta, NATIVE, VersionMeta, World};
@@ -139,14 +139,10 @@ impl Broker {
self.log(from, &format!("message without \"body\", ignored: {}", truncate(line, 500)));
return;
};
let own_id = match obj.get("id") {
Some(Value::String(s)) => Some(s.clone()),
Some(Value::Number(n)) => Some(n.to_string()),
_ => None,
};
let own_id = obj.get("id").and_then(Value::as_str);
let to = obj.get("to").and_then(Value::as_str);
let reply_to = obj.get("reply_to").and_then(Value::as_str);
self.send(from, to, own_id.as_deref(), reply_to, body);
self.send(from, to, own_id, reply_to, body);
}
fn deliver(&self, env: Envelope) {
@@ -178,13 +174,25 @@ impl Broker {
self.op_locks.lock().unwrap().entry(id.to_string()).or_default().clone()
}
/// Mounts of a running actor. `/actor` hides every `data/` folder.
pub fn mounts(&self, id: &str) -> Vec<Mount> {
vec![
Mount { guest: "/actor".into(), host: self.world.actors_root(), writable: false },
Mount { guest: "/public".into(), host: self.world.public_dir(id), writable: true },
Mount { guest: "/data".into(), host: self.world.data_dir(id), writable: true },
]
/// What an instance of `id` gets (see PROTOCOL.md). A candidate runs in
/// `scratch`, which holds a copy of the actor's `data/` and `public/`,
/// and has no HTTP.
pub fn instance_config(&self, id: &str, version: u64, scratch: Option<&Path>) -> InstanceConfig {
let own = scratch.map_or_else(|| self.world.actor_dir(id), Path::to_path_buf);
let mut env = vec![("SAUSAGE_ACTOR".into(), id.to_string()), ("SAUSAGE_VERSION".into(), version.to_string())];
if scratch.is_some() {
env.push(("SAUSAGE_CANDIDATE".into(), "1".into()));
}
InstanceConfig {
mounts: vec![
Mount { guest: "/actor".into(), host: self.world.actors_root(), writable: false },
Mount { guest: "/public".into(), host: own.join("public"), writable: true },
Mount { guest: "/data".into(), host: own.join("data"), writable: true },
],
allow_http: scratch.is_none(),
stderr_log: own.join("stderr.log"),
env,
}
}
// ---------------------------------------------------------------------