Sausage spike: host (broker, supervisors, commit-on-close fs, cargo actor, console), agent actor, examples

This commit is contained in:
2026-10-15 04:47:00 +01:00
commit 83bbbb33a8
29 changed files with 6602 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "notes"
version = "0.1.0"
edition = "2024"
[dependencies]
serde_json = "1"
+37
View File
@@ -0,0 +1,37 @@
//! Keeps a list of notes in /data/notes.json and publishes them as
//! /public/notes.txt.
use serde_json::{Value, json};
use std::io::{BufRead, Write};
const DATA: &str = "/data/notes.json";
fn save(notes: &[String]) {
std::fs::write(DATA, serde_json::to_string(notes).unwrap()).unwrap();
std::fs::write("/public/notes.txt", notes.join("\n") + "\n").unwrap();
}
fn main() {
let mut notes: Vec<String> = std::fs::read_to_string(DATA)
.ok()
.and_then(|s| serde_json::from_str(&s).ok())
.unwrap_or_default();
let mut out = std::io::stdout().lock();
for line in std::io::stdin().lock().lines() {
let Ok(line) = line else { break };
let Ok(msg) = serde_json::from_str::<Value>(&line) else { continue };
let body = &msg["body"];
let reply = match body["type"].as_str() {
Some("shutdown") => break,
Some("add") => {
notes.push(body["text"].as_str().unwrap_or_default().to_string());
save(&notes);
json!({"type": "added", "count": notes.len()})
}
Some("list") => json!({"type": "notes", "items": notes}),
Some("crash") => panic!("asked to crash"),
_ => json!({"type": "error", "reason": "unknown message"}),
};
writeln!(out, "{}", json!({"to": msg["from"], "reply_to": msg["id"], "body": reply})).unwrap();
out.flush().unwrap();
}
}
+4
View File
@@ -0,0 +1,4 @@
{"send": {"type": "add", "text": "test note"}}
{"expect": {"type": "added"}}
{"send": {"type": "list"}}
{"expect": {"type": "notes"}}