mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-01-16 22:46:27 +03:00
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 {
|
fn default_presence_cleanup_period() -> u64 {
|
||||||
1 * 60 * 60
|
24 * 60 * 60
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_presence_cleanup_limit() -> u64 {
|
fn default_presence_cleanup_limit() -> u64 {
|
||||||
|
|
|
@ -219,17 +219,22 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut timers = FuturesUnordered::new();
|
let mut timers = FuturesUnordered::new();
|
||||||
let mut timers_timestamp: HashMap<OwnedUserId, u64> = HashMap::new();
|
let mut timers_timestamp: HashMap<OwnedUserId, u64> = HashMap::new();
|
||||||
let idle_timeout = Duration::from_secs(services().globals.presence_idle_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(
|
|
||||||
idle_timeout,
|
|
||||||
UserId::parse_with_server_name("conduit", services().globals.server_name())
|
|
||||||
.expect("Conduit user always exists"),
|
|
||||||
));
|
|
||||||
|
|
||||||
tokio::spawn(async move {
|
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());
|
||||||
|
|
||||||
|
// TODO: Get rid of this hack (hinting correct types to rustc)
|
||||||
|
timers.push(create_presence_timer(
|
||||||
|
idle_timeout,
|
||||||
|
UserId::parse_with_server_name("conduit", services().globals.server_name())
|
||||||
|
.expect("Conduit user always exists"),
|
||||||
|
));
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
Some(user_id) = timers.next() => {
|
Some(user_id) = timers.next() => {
|
||||||
|
@ -298,16 +303,17 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn presence_cleanup(&self) -> Result<()> {
|
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 userid_presenceupdate = self.userid_presenceupdate.clone();
|
||||||
let roomuserid_presenceevent = self.roomuserid_presenceevent.clone();
|
let roomuserid_presenceevent = self.roomuserid_presenceevent.clone();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
// Wait for services to be created
|
||||||
sleep(period).await;
|
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 mut removed_events: u64 = 0;
|
||||||
let age_limit_curr =
|
let age_limit_curr =
|
||||||
millis_since_unix_epoch().saturating_sub(age_limit.as_millis() as u64);
|
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!");
|
info!("Cleaned up {removed_events} stale presence events!");
|
||||||
|
sleep(period).await;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue