db5adc9324
Removed ort/ndarray/image (ONNX Runtime inference) and sqlx (Postgres audit write). inference::detect() and the Postgres half of reporter::report() are now stubs with a comment for what real code goes there. Redis Streams XREADGROUP loop and the Redis pub/sub alert stay real. Verified with a clean cargo check --all-targets (0 warnings).
42 lines
1.4 KiB
Rust
42 lines
1.4 KiB
Rust
use redis::AsyncCommands;
|
|
use tracing::info;
|
|
|
|
use crate::inference::Detection;
|
|
|
|
const ALERT_CHANNEL: &str = "channel:print_alerts";
|
|
|
|
/// Fast-paths a failure alert out to whatever's listening.
|
|
pub struct Reporter {
|
|
redis: redis::aio::MultiplexedConnection,
|
|
}
|
|
|
|
impl Reporter {
|
|
pub async fn connect(redis_url: &str) -> anyhow::Result<Self> {
|
|
let client = redis::Client::open(redis_url)?;
|
|
let redis = client.get_multiplexed_tokio_connection().await?;
|
|
Ok(Self { redis })
|
|
}
|
|
|
|
/// Publishes to Redis (real — this is what `continuum-backend`'s
|
|
/// WebSocket fan-out subscribes to, for live operator-console alerts).
|
|
///
|
|
/// A real version would also `INSERT` into Postgres here via `sqlx` for
|
|
/// the permanent audit trail — that's left as a `println!` for now;
|
|
/// come back to it once async SQL feels comfortable.
|
|
pub async fn report(&mut self, printer_id: &str, detections: &[Detection]) -> anyhow::Result<()> {
|
|
let best = &detections[0];
|
|
info!(printer_id, label = %best.label, confidence = best.confidence, "reporting print failure");
|
|
|
|
let payload = serde_json::json!({
|
|
"printerId": printer_id,
|
|
"label": best.label,
|
|
"confidence": best.confidence,
|
|
});
|
|
self.redis.publish::<_, _, ()>(ALERT_CHANNEL, payload.to_string()).await?;
|
|
|
|
println!("(would also INSERT this alert into Postgres for the audit trail)");
|
|
|
|
Ok(())
|
|
}
|
|
}
|