World folder is the source of truth
- actor/<id>/ holds actor.wasm, actor.json, source/, public/, data/, versions/ - the broker boots by scanning actor/; a changed actor.wasm is an upgrade, a rejected one stays in versions/ with a reason and the files come back - /actor hides every data/ folder - subscriptions live in the subscriber's actor.json - cargo installs the SDK and points sausage-actor at it; no build limits - PROTOCOL.md
This commit is contained in:
+6
-6
@@ -7,7 +7,7 @@ use clap::{Parser, Subcommand};
|
||||
use include_dir::{Dir, include_dir};
|
||||
use serde_json::json;
|
||||
|
||||
use sausage::world::{self, VersionMeta, World};
|
||||
use sausage::world::{self, ActorMeta, VersionMeta, World};
|
||||
use sausage::{Broker, Host, cargo_actor, console, runtime};
|
||||
|
||||
/// The source of the agent actor. `init` builds it like any other actor.
|
||||
@@ -69,9 +69,8 @@ async fn init(dir: PathBuf) -> Result<()> {
|
||||
let token = setting("SAUSAGE_API_TOKEN", "API token", None)?;
|
||||
|
||||
let world = World::create(&dir)?;
|
||||
let mut reg = world.load_registry()?;
|
||||
reg.subscriptions.entry("agent".into()).or_default().insert("console".into());
|
||||
world.save_registry(®)?;
|
||||
let console = ActorMeta { subscriptions: ["agent".to_string()].into(), ..world.read_meta(console::ID) };
|
||||
world.write_meta(console::ID, &console)?;
|
||||
|
||||
// The agent's private configuration. Only the agent can read /data.
|
||||
world.ensure_actor_dirs("agent")?;
|
||||
@@ -84,11 +83,11 @@ async fn init(dir: PathBuf) -> Result<()> {
|
||||
std::fs::set_permissions(&config_path, std::fs::Permissions::from_mode(0o600))?;
|
||||
}
|
||||
|
||||
let source = world.root.join("broker").join("seed").join("agent");
|
||||
let source = world.scratch_dir().join("seed").join("agent");
|
||||
std::fs::create_dir_all(&source)?;
|
||||
AGENT_SOURCE.extract(&source).context("extract agent source")?;
|
||||
println!("Building the agent actor (the first build takes a few minutes) …");
|
||||
let out = cargo_actor::Cargo::new(world.clone()).build(&source).await.context("build agent")?;
|
||||
let out = cargo_actor::Cargo::new(world.clone())?.build(&source).await.context("build agent")?;
|
||||
println!("Built in {:.1} s.", out.seconds);
|
||||
|
||||
let broker = Broker::new(world.clone(), runtime::Runtime::new()?)?;
|
||||
@@ -99,6 +98,7 @@ async fn init(dir: PathBuf) -> Result<()> {
|
||||
built_by: Some(cargo_actor::ID.into()),
|
||||
requested_by: "init".into(),
|
||||
created_at: world::now(),
|
||||
rejected: None,
|
||||
};
|
||||
broker.create_actor("agent", &out.wasm, Some(&source), meta, false).await?;
|
||||
println!("World ready. Start it with: sausage run {}", dir.display());
|
||||
|
||||
Reference in New Issue
Block a user