fix(presence): allow services to start before running tasks
This commit is contained in:
parent
77b555f2d6
commit
dd85316bd9
2 changed files with 22 additions and 15 deletions
|
@ -276,7 +276,7 @@ fn default_presence_offline_timeout() -> u64 {
|
|||
}
|
||||
|
||||
fn default_presence_cleanup_period() -> u64 {
|
||||
1 * 60 * 60
|
||||
24 * 60 * 60
|
||||
}
|
||||
|
||||
fn default_presence_cleanup_limit() -> u64 {
|
||||
|
|
|
@ -219,8 +219,14 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
|
|||
) -> Result<()> {
|
||||
let mut timers = FuturesUnordered::new();
|
||||
let mut timers_timestamp: HashMap<OwnedUserId, u64> = HashMap::new();
|
||||
|
||||
tokio::spawn(async move {
|
||||
// Wait for services to be created
|
||||
sleep(Duration::from_secs(15)).await;
|
||||
|
||||
let idle_timeout = Duration::from_secs(services().globals.presence_idle_timeout());
|
||||
let offline_timeout = Duration::from_secs(services().globals.presence_offline_timeout());
|
||||
let offline_timeout =
|
||||
Duration::from_secs(services().globals.presence_offline_timeout());
|
||||
|
||||
// TODO: Get rid of this hack (hinting correct types to rustc)
|
||||
timers.push(create_presence_timer(
|
||||
|
@ -229,7 +235,6 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
|
|||
.expect("Conduit user always exists"),
|
||||
));
|
||||
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
tokio::select! {
|
||||
Some(user_id) = timers.next() => {
|
||||
|
@ -298,16 +303,17 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
|
|||
}
|
||||
|
||||
fn presence_cleanup(&self) -> Result<()> {
|
||||
let period = Duration::from_secs(services().globals.presence_cleanup_period());
|
||||
let age_limit = Duration::from_secs(services().globals.presence_cleanup_limit());
|
||||
|
||||
let userid_presenceupdate = self.userid_presenceupdate.clone();
|
||||
let roomuserid_presenceevent = self.roomuserid_presenceevent.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
sleep(period).await;
|
||||
// Wait for services to be created
|
||||
sleep(Duration::from_secs(15)).await;
|
||||
|
||||
let period = Duration::from_secs(services().globals.presence_cleanup_period());
|
||||
let age_limit = Duration::from_secs(services().globals.presence_cleanup_limit());
|
||||
|
||||
loop {
|
||||
let mut removed_events: u64 = 0;
|
||||
let age_limit_curr =
|
||||
millis_since_unix_epoch().saturating_sub(age_limit.as_millis() as u64);
|
||||
|
@ -352,6 +358,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
|
|||
}
|
||||
|
||||
info!("Cleaned up {removed_events} stale presence events!");
|
||||
sleep(period).await;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue