Skip to content

Commit

Permalink
add delay before starting updates check
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Volk <[email protected]>
  • Loading branch information
jevolk committed Dec 3, 2024
1 parent 7d6710c commit 89a158a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/service/updates/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{sync::Arc, time::Duration};

use async_trait::async_trait;
use conduit::{debug, info, warn, Result};
use conduit::{debug, info, warn, Result, Server};
use database::{Deserialized, Map};
use ruma::events::room::message::RoomMessageEventContent;
use serde::Deserialize;
Expand All @@ -23,6 +23,7 @@ struct Services {
admin: Dep<admin::Service>,
client: Dep<client::Service>,
globals: Dep<globals::Service>,
server: Arc<Server>,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -52,11 +53,12 @@ impl crate::Service for Service {
globals: args.depend::<globals::Service>("globals"),
admin: args.depend::<admin::Service>("admin"),
client: args.depend::<client::Service>("client"),
server: args.server.clone(),
},
}))
}

#[tracing::instrument(skip_all, name = "updates", level = "trace")]
#[tracing::instrument(skip_all, name = "updates", level = "debug")]
async fn worker(self: Arc<Self>) -> Result<()> {
if !self.services.globals.allow_check_for_updates() {
debug!("Disabling update check");
Expand All @@ -65,6 +67,7 @@ impl crate::Service for Service {

let mut i = interval(self.interval);
i.set_missed_tick_behavior(MissedTickBehavior::Delay);
i.reset_after(self.interval);
loop {
tokio::select! {
() = self.interrupt.notified() => break,
Expand All @@ -85,8 +88,10 @@ impl crate::Service for Service {
}

impl Service {
#[tracing::instrument(skip_all, level = "trace")]
#[tracing::instrument(skip_all)]
async fn check(&self) -> Result<()> {
debug_assert!(self.services.server.running(), "server must not be shutting down");

let response = self
.services
.client
Expand All @@ -108,6 +113,7 @@ impl Service {
Ok(())
}

#[tracing::instrument(skip_all)]
async fn handle(&self, update: &CheckForUpdatesResponseEntry) {
info!("{} {:#}", update.date, update.message);
self.services
Expand Down

0 comments on commit 89a158a

Please sign in to comment.