mirror of
https://github.com/2e3s/awatcher.git
synced 2025-06-06 11:35:46 +00:00
Use a single now time
This commit is contained in:
parent
ea215b432d
commit
0434aa103b
@ -38,9 +38,10 @@ impl State {
|
|||||||
seconds_since_input: u32,
|
seconds_since_input: u32,
|
||||||
client: &Arc<ReportClient>,
|
client: &Arc<ReportClient>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
let now = Utc::now();
|
||||||
let time_since_input = Duration::seconds(i64::from(seconds_since_input));
|
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
|
if self.is_idle
|
||||||
&& u64::from(seconds_since_input) < self.idle_timeout.num_seconds().try_into().unwrap()
|
&& u64::from(seconds_since_input) < self.idle_timeout.num_seconds().try_into().unwrap()
|
||||||
@ -56,9 +57,7 @@ impl State {
|
|||||||
self.is_changed = true;
|
self.is_changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.send_ping(client).await?;
|
self.send_ping(now, client).await
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_reactive(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
pub async fn send_reactive(&mut self, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||||
@ -67,12 +66,10 @@ impl State {
|
|||||||
self.last_input_time = now;
|
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<()> {
|
async fn send_ping(&mut self, now: DateTime<Utc>, client: &Arc<ReportClient>) -> anyhow::Result<()> {
|
||||||
let now = Utc::now();
|
|
||||||
|
|
||||||
if self.is_changed {
|
if self.is_changed {
|
||||||
let result = if self.is_idle {
|
let result = if self.is_idle {
|
||||||
debug!("Reporting as changed to idle");
|
debug!("Reporting as changed to idle");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user