Skip to content

Commit

Permalink
Use a single now time
Browse files Browse the repository at this point in the history
  • Loading branch information
2e3s committed May 17, 2024
1 parent ea215b4 commit 0434aa1
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions watchers/src/watchers/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ impl State {
seconds_since_input: u32,
client: &Arc<ReportClient>,
) -> anyhow::Result<()> {
let now = Utc::now();
let time_since_input = Duration::seconds(i64::from(seconds_since_input));

self.last_input_time = Utc::now() - time_since_input;
self.last_input_time = now - time_since_input;

if self.is_idle
&& u64::from(seconds_since_input) < self.idle_timeout.num_seconds().try_into().unwrap()
Expand All @@ -56,9 +57,7 @@ impl State {
self.is_changed = true;
}

self.send_ping(client).await?;

Ok(())
self.send_ping(now, client).await
}

pub async fn send_reactive(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
Expand All @@ -67,12 +66,10 @@ impl State {
self.last_input_time = now;
}

self.send_ping(client).await
self.send_ping(now, client).await
}

async fn send_ping(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
let now = Utc::now();

async fn send_ping(&mut self, now: DateTime<Utc>, client: &Arc<ReportClient>) -> anyhow::Result<()> {
if self.is_changed {
let result = if self.is_idle {
debug!("Reporting as changed to idle");
Expand Down

0 comments on commit 0434aa1

Please sign in to comment.