-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed HistoricalUptimeUpdater (#5097)
- Loading branch information
Showing
2 changed files
with
9 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2021 - Nym Technologies SA <[email protected]> | ||
// Copyright 2021-2024 - Nym Technologies SA <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
use crate::node_status_api::models::{ | ||
|
@@ -9,7 +9,7 @@ use crate::storage::NymApiStorage; | |
use nym_task::{TaskClient, TaskManager}; | ||
use std::time::Duration; | ||
use time::{OffsetDateTime, PrimitiveDateTime, Time}; | ||
use tokio::time::{interval, sleep}; | ||
use tokio::time::{interval_at, Instant}; | ||
use tracing::error; | ||
use tracing::{info, trace, warn}; | ||
|
||
|
@@ -93,22 +93,16 @@ impl HistoricalUptimeUpdater { | |
"waiting until {update_datetime} to update the historical uptimes for the first time ({} seconds left)", time_left.as_secs() | ||
); | ||
|
||
tokio::select! { | ||
biased; | ||
_ = shutdown.recv() => { | ||
trace!("UpdateHandler: Received shutdown"); | ||
} | ||
_ = sleep(time_left) => {} | ||
} | ||
|
||
let mut interval = interval(ONE_DAY); | ||
let start = Instant::now() + time_left; | ||
let mut interval = interval_at(start, ONE_DAY); | ||
while !shutdown.is_shutdown() { | ||
tokio::select! { | ||
biased; | ||
_ = shutdown.recv() => { | ||
trace!("UpdateHandler: Received shutdown"); | ||
} | ||
_ = interval.tick() => { | ||
info!("updating historical uptimes of nodes"); | ||
// we don't want to have another select here; uptime update is relatively speedy | ||
// and we don't want to exit while we're in the middle of database update | ||
if let Err(err) = self.update_uptimes().await { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters