Skip to content

Commit

Permalink
Adjust Worker::listen_for_heartbeat to use Duration
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy committed May 26, 2024
1 parent f1ef50d commit 8a2c16d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/worker/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ use crate::{proto::HeartbeatStatus, Error};
use std::{
error::Error as StdError,
sync::{atomic, Arc},
time,
time::{self, Duration},
};
use tokio::io::{AsyncBufRead, AsyncWrite};
use tokio::time::sleep as tokio_sleep;

const CHECK_STATE_INTERVAL: Duration = Duration::from_millis(100);
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);

impl<S, E> Worker<S, E>
where
S: AsyncBufRead + AsyncWrite + Send + Unpin,
Expand Down Expand Up @@ -37,7 +38,7 @@ where
let mut last = time::Instant::now();

loop {
tokio_sleep(time::Duration::from_millis(CHECK_STATE_INTERVAL_MILLIS)).await;
tokio_sleep(CHECK_STATE_INTERVAL).await;

// has a worker failed?
let worker_failure = target == STATUS_RUNNING
Expand All @@ -53,7 +54,7 @@ where
break Ok(false);
}

if last.elapsed().as_secs() < HEARTBEAT_INTERVAL_SECS {
if last.elapsed() < HEARTBEAT_INTERVAL {
// don't sent a heartbeat yet
continue;
}
Expand Down

0 comments on commit 8a2c16d

Please sign in to comment.