huskies: merge 918
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
//! This file contains only the `run` entrypoint and `build_gateway_route` wiring.
|
||||
|
||||
use crate::http::gateway::*;
|
||||
use crate::rebuild::ShutdownReason;
|
||||
use crate::service::gateway::{self, GatewayState};
|
||||
use poem::EndpointExt;
|
||||
use std::path::Path;
|
||||
@@ -118,7 +119,7 @@ pub async fn run(config_path: &Path, port: u16) -> Result<(), std::io::Error> {
|
||||
.iter()
|
||||
.map(|(name, entry)| (name.clone(), entry.url.clone()))
|
||||
.collect();
|
||||
let bot_abort = gateway::io::spawn_gateway_bot(
|
||||
let (bot_abort, bot_shutdown_tx) = gateway::io::spawn_gateway_bot(
|
||||
&config_dir,
|
||||
Arc::clone(&state_arc.active_project),
|
||||
gateway_projects,
|
||||
@@ -127,16 +128,29 @@ pub async fn run(config_path: &Path, port: u16) -> Result<(), std::io::Error> {
|
||||
Some(state_arc.event_tx.clone()),
|
||||
);
|
||||
*state_arc.bot_handle.lock().await = bot_abort;
|
||||
*state_arc.bot_shutdown_tx.lock().await = Some(bot_shutdown_tx);
|
||||
|
||||
let route = build_gateway_route(state_arc);
|
||||
let route = build_gateway_route(state_arc.clone());
|
||||
|
||||
let host = std::env::var("HUSKIES_HOST").unwrap_or_else(|_| "127.0.0.1".to_string());
|
||||
let addr = format!("{host}:{port}");
|
||||
crate::slog!("[gateway] Listening on {addr}");
|
||||
|
||||
poem::Server::new(poem::listener::TcpListener::bind(&addr))
|
||||
let result = poem::Server::new(poem::listener::TcpListener::bind(&addr))
|
||||
.run(route)
|
||||
.await
|
||||
.await;
|
||||
|
||||
// Best-effort shutdown notification: signal the Matrix bot so it can post
|
||||
// "going offline" before the process exits. Mirror of main.rs:346.
|
||||
{
|
||||
let guard = state_arc.bot_shutdown_tx.lock().await;
|
||||
if let Some(tx) = guard.as_ref() {
|
||||
let _ = tx.send(Some(ShutdownReason::Manual));
|
||||
}
|
||||
}
|
||||
tokio::time::sleep(std::time::Duration::from_millis(1500)).await;
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user