client: sort out shutdown procedure and harmonize with socks5-client (#2695)

* common/task: rename ShutdownNotifier to TaskManager

* nym-client: return boxed error

* nym-client: enable graceful shutdown

* nym-client: task wait on shutdown to instead exit on closed channel

* Fix build

* Fix unused

* changelog: update
This commit is contained in:
Jon Häggblad
2022-12-14 17:13:00 +01:00
committed by GitHub
parent f6a79ce7c3
commit eb07ec8580
64 changed files with 325 additions and 277 deletions
@@ -1,5 +1,5 @@
use log::info;
use task::ShutdownListener;
use task::TaskClient;
use crate::country_statistics::country_nodes_distribution::CountryNodesDistribution;
use crate::COUNTRY_DATA_REFRESH_INTERVAL;
@@ -8,11 +8,11 @@ use crate::state::ExplorerApiStateContext;
pub(crate) struct CountryStatisticsDistributionTask {
state: ExplorerApiStateContext,
shutdown: ShutdownListener,
shutdown: TaskClient,
}
impl CountryStatisticsDistributionTask {
pub(crate) fn new(state: ExplorerApiStateContext, shutdown: ShutdownListener) -> Self {
pub(crate) fn new(state: ExplorerApiStateContext, shutdown: TaskClient) -> Self {
CountryStatisticsDistributionTask { state, shutdown }
}
@@ -4,15 +4,15 @@
use crate::mix_nodes::location::Location;
use crate::state::ExplorerApiStateContext;
use log::{info, warn};
use task::ShutdownListener;
use task::TaskClient;
pub(crate) struct GeoLocateTask {
state: ExplorerApiStateContext,
shutdown: ShutdownListener,
shutdown: TaskClient,
}
impl GeoLocateTask {
pub(crate) fn new(state: ExplorerApiStateContext, shutdown: ShutdownListener) -> Self {
pub(crate) fn new(state: ExplorerApiStateContext, shutdown: TaskClient) -> Self {
GeoLocateTask { state, shutdown }
}
+3 -3
View File
@@ -8,7 +8,7 @@ use dotenv::dotenv;
use log::info;
use logging::setup_logging;
use network_defaults::setup_env;
use task::ShutdownNotifier;
use task::TaskManager;
mod buy_terms;
pub(crate) mod cache;
@@ -57,7 +57,7 @@ impl ExplorerApi {
let nym_api_url = self.state.inner.validator_client.api_endpoint();
info!("Using validator API - {}", nym_api_url);
let shutdown = ShutdownNotifier::default();
let shutdown = TaskManager::default();
// spawn concurrent tasks
crate::tasks::ExplorerApiTasks::new(self.state.clone(), shutdown.subscribe()).start();
@@ -78,7 +78,7 @@ impl ExplorerApi {
self.wait_for_interrupt(shutdown).await
}
async fn wait_for_interrupt(&self, mut shutdown: ShutdownNotifier) {
async fn wait_for_interrupt(&self, mut shutdown: TaskManager) {
wait_for_signal().await;
log::info!("Sending shutdown");
+3 -3
View File
@@ -4,7 +4,7 @@
use std::future::Future;
use mixnet_contract_common::GatewayBond;
use task::ShutdownListener;
use task::TaskClient;
use validator_client::models::MixNodeBondAnnotated;
use validator_client::nymd::error::NymdError;
use validator_client::nymd::{Paging, QueryNymdClient, ValidatorResponse};
@@ -15,11 +15,11 @@ use crate::state::ExplorerApiStateContext;
pub(crate) struct ExplorerApiTasks {
state: ExplorerApiStateContext,
shutdown: ShutdownListener,
shutdown: TaskClient,
}
impl ExplorerApiTasks {
pub(crate) fn new(state: ExplorerApiStateContext, shutdown: ShutdownListener) -> Self {
pub(crate) fn new(state: ExplorerApiStateContext, shutdown: TaskClient) -> Self {
ExplorerApiTasks { state, shutdown }
}