Skip to content

Commit

Permalink
chore: Move to service API
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Jan 22, 2025
1 parent 0e4b949 commit 4ac4ecf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ impl Cli {
shutdown_tx.send(crate::ShutdownKind::Normal).ok();
});

self.service.spawn_services(&config, &shutdown_rx)?;

match (self.command, mode) {
(Commands::Agent(agent), Admin::Agent(ready)) => {
agent.run(locality, config, ready, shutdown_rx).await
Expand Down
5 changes: 4 additions & 1 deletion src/components/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ impl Agent {
None
};

crate::codec::qcmp::spawn(self.qcmp_socket, shutdown_rx.clone())?;
crate::cli::Service::default()
.qcmp()
.qcmp_port(crate::net::socket_port(&self.qcmp_socket))
.spawn_services(&config, &shutdown_rx)?;
shutdown_rx.changed().await.map_err(From::from)
}
}
15 changes: 4 additions & 11 deletions src/components/manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,12 @@ impl Manage {
None
};

use futures::TryFutureExt as _;
let server_task = tokio::spawn(
crate::net::xds::server::ControlPlane::from_arc(
config,
crate::components::admin::IDLE_REQUEST_INTERVAL,
)
.management_server(self.listener)?,
)
.map_err(From::from)
.and_then(std::future::ready);
crate::cli::Service::default()
.xds()
.xds_port(self.listener.port())
.spawn_services(&config, &shutdown_rx)?;

tokio::select! {
result = server_task => result,
result = provider_task => result?,
result = shutdown_rx.changed() => result.map_err(From::from),
}
Expand Down
26 changes: 8 additions & 18 deletions src/components/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ impl Relay {
mut shutdown_rx,
}: RunArgs<Ready>,
) -> crate::Result<()> {
use crate::net::xds::server::ControlPlane;

let xds_server = ControlPlane::from_arc(config.clone(), ready.idle_request_interval)
.management_server(self.xds_listener)?;
let mds_server = tokio::spawn(
ControlPlane::from_arc(config.clone(), ready.idle_request_interval)
.relay_server(self.mds_listener)?,
);

let _provider_task = self.provider.map(|provider| {
let config = config.clone();
let provider_is_healthy = ready.provider_is_healthy.clone();
Expand Down Expand Up @@ -134,14 +125,13 @@ impl Relay {
}
});

tokio::select! {
result = xds_server => {
result
}
result = mds_server => {
result?
}
result = shutdown_rx.changed() => result.map_err(From::from),
}
crate::cli::Service::default()
.xds()
.xds_port(self.xds_listener.port())
.mds()
.mds_port(self.mds_listener.port())
.spawn_services(&config, &shutdown_rx)?;

shutdown_rx.changed().await.map_err(From::from)
}
}

0 comments on commit 4ac4ecf

Please sign in to comment.