Skip to content

Commit

Permalink
fixed HistoricalUptimeUpdater (#5097)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstuczyn authored Nov 5, 2024
1 parent d03c5b3 commit fd8dc63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
16 changes: 5 additions & 11 deletions nym-api/src/node_status_api/uptime_updater.rs
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::{
Expand All @@ -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};

Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions nym-api/src/support/storage/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,8 @@ impl StorageManager {
since: i64,
until: i64,
) -> Result<Vec<ActiveGateway>, sqlx::Error> {
sqlx::query_as(
sqlx::query_as!(
ActiveGateway,
r#"
SELECT DISTINCT identity, node_id as "node_id: NodeId", id
FROM gateway_details
Expand All @@ -993,9 +994,9 @@ impl StorageManager {
SELECT 1 FROM gateway_status WHERE timestamp > ? AND timestamp < ?
)
"#,
since,
until
)
.bind(since)
.bind(until)
.fetch_all(&self.connection_pool)
.await
}
Expand Down

0 comments on commit fd8dc63

Please sign in to comment.