Instrument rpc::Server::start and reduce cleanup timeout again

This commit is contained in:
Antonio Scandurra 2022-12-14 11:42:12 +01:00
parent 63e7b9189d
commit 674fddac87

View file

@ -58,7 +58,7 @@ use tower::ServiceBuilder;
use tracing::{info_span, instrument, Instrument};
pub const RECONNECT_TIMEOUT: Duration = Duration::from_secs(5);
pub const CLEANUP_TIMEOUT: Duration = Duration::from_secs(20);
pub const CLEANUP_TIMEOUT: Duration = Duration::from_secs(10);
lazy_static! {
static ref METRIC_CONNECTIONS: IntGauge =
@ -239,15 +239,27 @@ impl Server {
}
pub async fn start(&self) -> Result<()> {
self.app_state.db.delete_stale_projects().await?;
let db = self.app_state.db.clone();
let peer = self.peer.clone();
let timeout = self.executor.sleep(CLEANUP_TIMEOUT);
let pool = self.connection_pool.clone();
let live_kit_client = self.app_state.live_kit_client.clone();
self.executor.spawn_detached(async move {
let span = info_span!("start server");
let span_enter = span.enter();
tracing::info!("begin deleting stale projects");
self.app_state.db.delete_stale_projects().await?;
tracing::info!("finish deleting stale projects");
drop(span_enter);
self.executor.spawn_detached(
async move {
tracing::info!("waiting for cleanup timeout");
timeout.await;
tracing::info!("cleanup timeout expired, retrieving stale rooms");
if let Some(room_ids) = db.stale_room_ids().await.trace_err() {
tracing::info!(stale_room_count = room_ids.len(), "retrieved stale rooms");
for room_id in room_ids {
let mut contacts_to_update = HashSet::default();
let mut canceled_calls_to_user_ids = Vec::new();
@ -255,6 +267,11 @@ impl Server {
let mut delete_live_kit_room = false;
if let Ok(mut refreshed_room) = db.refresh_room(room_id).await {
tracing::info!(
room_id = room_id.0,
new_participant_count = refreshed_room.room.participants.len(),
"refreshed room"
);
room_updated(&refreshed_room.room, &peer);
contacts_to_update
.extend(refreshed_room.stale_participant_user_ids.iter().copied());
@ -293,7 +310,8 @@ impl Server {
..
} = contact
{
for contact_conn_id in pool.user_connection_ids(contact_user_id)
for contact_conn_id in
pool.user_connection_ids(contact_user_id)
{
peer.send(
contact_conn_id,
@ -320,7 +338,9 @@ impl Server {
}
}
}
});
}
.instrument(span),
);
Ok(())
}