increase delays a bit

This commit is contained in:
phiresky 2023-08-24 00:46:01 +02:00
parent 942510650b
commit 7fe2724c8a

View File

@ -23,7 +23,7 @@ use tokio::{sync::mpsc::UnboundedSender, time::sleep};
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
/// save state to db every n sends if there's no failures (otherwise state is saved after every attempt) /// save state to db every n sends if there's no failures (otherwise state is saved after every attempt)
static CHECK_SAVE_STATE_EVERY_IT: i64 = 100; static CHECK_SAVE_STATE_EVERY_IT: i64 = 100;
static SAVE_STATE_EVERY_TIME: Duration = Duration::from_secs(10); static SAVE_STATE_EVERY_TIME: Duration = Duration::from_secs(60);
pub(crate) struct InstanceWorker { pub(crate) struct InstanceWorker {
instance: Instance, instance: Instance,
@ -109,7 +109,7 @@ impl InstanceWorker {
if id == latest_id { if id == latest_id {
// no more work to be done, wait before rechecking // no more work to be done, wait before rechecking
tokio::select! { tokio::select! {
() = sleep(Duration::from_secs(10)) => {}, () = sleep(Duration::from_secs(30)) => {},
() = self.stop.cancelled() => {} () = self.stop.cancelled() => {}
} }
return Ok(()); return Ok(());
@ -212,14 +212,15 @@ impl InstanceWorker {
} }
async fn update_communities(&mut self, pool: &mut DbPool<'_>) -> Result<()> { async fn update_communities(&mut self, pool: &mut DbPool<'_>) -> Result<()> {
if (Utc::now() - self.last_full_communities_fetch) > chrono::Duration::seconds(600) { if (Utc::now() - self.last_full_communities_fetch) > chrono::Duration::hours(1) {
// process removals every 5min // process removals every hour
(self.followed_communities, self.last_full_communities_fetch) = self (self.followed_communities, self.last_full_communities_fetch) = self
.get_communities(pool, self.instance.id, self.last_full_communities_fetch) .get_communities(pool, self.instance.id, self.last_full_communities_fetch)
.await?; .await?;
self.last_incremental_communities_fetch = self.last_full_communities_fetch; self.last_incremental_communities_fetch = self.last_full_communities_fetch;
} }
if (Utc::now() - self.last_incremental_communities_fetch) > chrono::Duration::seconds(60) { if (Utc::now() - self.last_incremental_communities_fetch) > chrono::Duration::minutes(1) {
// process additions every minute
let (news, time) = self let (news, time) = self
.get_communities( .get_communities(
pool, pool,
@ -227,7 +228,6 @@ impl InstanceWorker {
self.last_incremental_communities_fetch, self.last_incremental_communities_fetch,
) )
.await?; .await?;
// process additions every 10s
self.followed_communities.extend(news); self.followed_communities.extend(news);
self.last_incremental_communities_fetch = time; self.last_incremental_communities_fetch = time;
} }