mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 03:31:45 +00:00
Improve tokio task execution (#1181)
* Add logging on shutdown
* Replace tokio::spawn with handle.spawn
* Upgrade tokio
* Add a task executor
* Beacon chain tasks use task executor
* Validator client tasks use task executor
* Rename runtime_handle to executor
* Add duration histograms; minor fixes
* Cleanup
* Fix logs
* Fix tests
* Remove random file
* Get enr dependency instead of libp2p
* Address some review comments
* Libp2p takes a TaskExecutor
* Ugly fix libp2p tests
* Move TaskExecutor to own file
* Upgrade Dockerfile rust version
* Minor fixes
* Revert "Ugly fix libp2p tests"
This reverts commit 58d4bb690f.
* Pretty fix libp2p tests
* Add spawn_without_exit; change Counter to Gauge
* Tidy
* Move log from RuntimeContext to TaskExecutor
* Fix errors
* Replace histogram with int_gauge for async tasks
* Fix todo
* Fix memory leak in test by exiting all spawned tasks at the end
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
use crate::{is_synced::is_synced, ProductionValidatorClient};
|
||||
use exit_future::Signal;
|
||||
use futures::{FutureExt, StreamExt};
|
||||
use futures::StreamExt;
|
||||
use slog::{error, info};
|
||||
use slot_clock::SlotClock;
|
||||
use tokio::time::{interval_at, Duration, Instant};
|
||||
use types::EthSpec;
|
||||
|
||||
/// Spawns a notifier service which periodically logs information about the node.
|
||||
pub fn spawn_notifier<T: EthSpec>(client: &ProductionValidatorClient<T>) -> Result<Signal, String> {
|
||||
pub fn spawn_notifier<T: EthSpec>(client: &ProductionValidatorClient<T>) -> Result<(), String> {
|
||||
let context = client.context.service_context("notifier".into());
|
||||
let runtime_handle = context.runtime_handle.clone();
|
||||
let log = context.log.clone();
|
||||
let executor = context.executor.clone();
|
||||
let duties_service = client.duties_service.clone();
|
||||
let allow_unsynced_beacon_node = client.config.allow_unsynced_beacon_node;
|
||||
|
||||
@@ -25,7 +23,7 @@ pub fn spawn_notifier<T: EthSpec>(client: &ProductionValidatorClient<T>) -> Resu
|
||||
let mut interval = interval_at(start_instant, slot_duration);
|
||||
|
||||
let interval_fut = async move {
|
||||
let log = &context.log;
|
||||
let log = context.log();
|
||||
|
||||
while interval.next().await.is_some() {
|
||||
if !is_synced(
|
||||
@@ -83,12 +81,6 @@ pub fn spawn_notifier<T: EthSpec>(client: &ProductionValidatorClient<T>) -> Resu
|
||||
}
|
||||
};
|
||||
|
||||
let (exit_signal, exit) = exit_future::signal();
|
||||
let future = futures::future::select(
|
||||
Box::pin(interval_fut),
|
||||
exit.map(move |_| info!(log, "Shutdown complete")),
|
||||
);
|
||||
runtime_handle.spawn(future);
|
||||
|
||||
Ok(exit_signal)
|
||||
executor.spawn(interval_fut, "validator_notifier");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user