Skip to content

Commit

Permalink
Use tokio::time::interval in heartbeat thread'
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy committed Sep 19, 2024
1 parent 1795c4f commit 79194c2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/proto/single/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ pub(crate) fn deser_as_optional_duration<'de, D>(value: D) -> Result<Option<Dura
where
D: Deserializer<'de>,
{
Ok(u64::deserialize(value)
.ok()
.map(|value| (Duration::from_secs(value))))
Ok(u64::deserialize(value).ok().map(Duration::from_secs))
}

pub(crate) fn ser_server_time<S>(value: &NaiveTime, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
5 changes: 3 additions & 2 deletions src/worker/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
sync::{atomic, Arc},
time::{self, Duration},
};
use tokio::time::sleep as tokio_sleep;

const CHECK_STATE_INTERVAL: Duration = Duration::from_millis(100);
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
Expand Down Expand Up @@ -34,9 +33,11 @@ where
let mut target = STATUS_RUNNING;

let mut last = time::Instant::now();
let mut check_state_interval = tokio::time::interval(CHECK_STATE_INTERVAL);
check_state_interval.tick().await;

loop {
tokio_sleep(CHECK_STATE_INTERVAL).await;
check_state_interval.tick().await;

// has a worker failed?
let worker_failure = target == STATUS_RUNNING
Expand Down
4 changes: 2 additions & 2 deletions src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl<E: StdError + 'static + Send> Worker<E> {
/// discontinued due to a signal from the Faktory server or a graceful shutdown signal,
/// calling this method will mean you are trying to run a _terminated_ worker which will
/// cause a panic. You will need to build and run a new worker instead.
///
///
/// You can check if the worker has been terminated with [`Worker::is_terminated`].
pub async fn run_one<Q>(&mut self, worker: usize, queues: &[Q]) -> Result<bool, Error>
where
Expand Down Expand Up @@ -440,7 +440,7 @@ impl<E: StdError + 'static + Send> Worker<E> {
/// Note that if you provided a shutdown signal when building this worker (see [`WorkerBuilder::with_graceful_shutdown`]),
/// and this signal resolved, the worker will be marked as terminated and calling this method will cause a panic.
/// You will need to build and run a new worker instead.
///
///
/// You can check if the worker has been terminated with [`Worker::is_terminated`].
pub async fn run<Q>(&mut self, queues: &[Q]) -> Result<StopDetails, Error>
where
Expand Down

0 comments on commit 79194c2

Please sign in to comment.