huskies: merge 669_story_migrate_slack_transport_to_status_broadcaster

This commit is contained in:
dave
2026-04-27 11:51:33 +00:00
parent 5da29c3d91
commit 25603bb8cb
3 changed files with 58 additions and 0 deletions
+31
View File
@@ -763,6 +763,37 @@ async fn main() -> Result<(), std::io::Error> {
watcher_rx_for_slack,
root.clone(),
);
// Subscribe to the status broadcaster if the slack_status_consumer toggle
// is enabled (default: true). Formats each StatusEvent via the common
// formatter and sends the resulting text to all configured Slack 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.slack_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!(
"[slack] Failed to send status event to {channel}: {e}"
);
}
}
}
crate::slog!("[slack] Status subscriber task exiting — broadcaster dropped");
});
}
}
} else {
drop(watcher_rx_for_slack);
}