huskies: merge 648_story_migrate_discord_transport_to_status_broadcaster

This commit is contained in:
dave
2026-04-27 13:57:19 +00:00
parent 9040d18f50
commit 6c8043d866
3 changed files with 58 additions and 0 deletions
+31
View File
@@ -809,6 +809,37 @@ async fn main() -> Result<(), std::io::Error> {
watcher_rx_for_discord,
root.clone(),
);
// Subscribe to the status broadcaster if the discord_status_consumer toggle
// is enabled (default: true). Formats each StatusEvent via the common
// formatter and sends the resulting text to all configured Discord channels.
// The task exits automatically when the broadcaster is dropped on shutdown.
{
use crate::service::status::format::format_status_event;
let status_enabled = config::ProjectConfig::load(root)
.map(|c| c.discord_status_consumer)
.unwrap_or(true);
if status_enabled {
let mut sub = ctx.services.status.subscribe();
let transport = Arc::clone(&ctx.transport) as Arc<dyn crate::chat::ChatTransport>;
let channels: Vec<String> = ctx.channel_ids.iter().cloned().collect();
tokio::spawn(async move {
while let Some(event) = sub.recv().await {
let plain = format_status_event(&event);
for channel in &channels {
if let Err(e) = transport.send_message(channel, &plain, "").await {
crate::slog!(
"[discord] Failed to send status event to {channel}: {e}"
);
}
}
}
crate::slog!("[discord] Status subscriber task exiting — broadcaster dropped");
});
}
}
} else {
drop(watcher_rx_for_discord);
}