make Gateway::new return Arc::Self
This commit is contained in:
@@ -113,7 +113,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let message_handler = config.admin_handler.map(|cmd| match cmd {
|
let message_handler = config.admin_handler.map(|cmd| match cmd {
|
||||||
AdminHandlerCommand::AdminHttp(config) => config.into_handler(),
|
AdminHandlerCommand::AdminHttp(config) => config.into_handler(),
|
||||||
});
|
});
|
||||||
let gateway = Arc::new(Gateway::new(config.gateway, token.clone(), message_handler).await);
|
let gateway = Gateway::new(config.gateway, token.clone(), message_handler).await;
|
||||||
|
|
||||||
let listener = TcpListener::bind(config.http_listen_addr).await.unwrap();
|
let listener = TcpListener::bind(config.http_listen_addr).await.unwrap();
|
||||||
info!("Listening for http on {}", config.http_listen_addr);
|
info!("Listening for http on {}", config.http_listen_addr);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use http::{Method, Request, Response, StatusCode};
|
|||||||
use http_body::Body;
|
use http_body::Body;
|
||||||
use http_body_util::BodyExt;
|
use http_body_util::BodyExt;
|
||||||
use prometheus_http_client::{AlertStatus, ExtractLabels};
|
use prometheus_http_client::{AlertStatus, ExtractLabels};
|
||||||
use std::{fmt::Write, net::SocketAddr, path::PathBuf, sync::Mutex, time::Duration};
|
use std::{fmt::Write, net::SocketAddr, path::PathBuf, sync::Arc, sync::Mutex, time::Duration};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
join,
|
join,
|
||||||
sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel},
|
sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel},
|
||||||
@@ -239,7 +239,7 @@ impl Gateway {
|
|||||||
config: GatewayConfig,
|
config: GatewayConfig,
|
||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
message_handler: Option<Box<dyn MessageHandler>>,
|
message_handler: Option<Box<dyn MessageHandler>>,
|
||||||
) -> Self {
|
) -> Arc<Self> {
|
||||||
let (signal_alert_mq_tx, signal_alert_mq_rx) = unbounded_channel();
|
let (signal_alert_mq_tx, signal_alert_mq_rx) = unbounded_channel();
|
||||||
|
|
||||||
let prometheus = config
|
let prometheus = config
|
||||||
@@ -256,7 +256,7 @@ impl Gateway {
|
|||||||
.clone()
|
.clone()
|
||||||
.map(|cc| ClaudeApi::new(cc).expect("Invalid claude config"));
|
.map(|cc| ClaudeApi::new(cc).expect("Invalid claude config"));
|
||||||
|
|
||||||
Self {
|
Arc::new(Self {
|
||||||
config,
|
config,
|
||||||
signal_alert_mq_tx,
|
signal_alert_mq_tx,
|
||||||
signal_alert_mq_rx: Mutex::new(Some(signal_alert_mq_rx)),
|
signal_alert_mq_rx: Mutex::new(Some(signal_alert_mq_rx)),
|
||||||
@@ -265,7 +265,7 @@ impl Gateway {
|
|||||||
log_handler,
|
log_handler,
|
||||||
message_handler,
|
message_handler,
|
||||||
claude,
|
claude,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run the gateway main loop, reconnecting to signal-cli on errors.
|
/// Run the gateway main loop, reconnecting to signal-cli on errors.
|
||||||
|
|||||||
Reference in New Issue
Block a user