This commit is contained in:
Antonio Scandurra 2022-12-14 19:25:07 +01:00
parent 930be6706f
commit 363e3cae4b
2 changed files with 23 additions and 3 deletions

View file

@ -231,9 +231,23 @@ impl Database {
.await
}
fn delete_stale_servers(&self, environment: &str, new_epoch: ServerEpoch) -> Result<()> {
self.transaction(|tx| async {
server::Entity::delete_many().filter(Condition::all().add())
pub async fn delete_stale_servers(
&self,
new_epoch: ServerEpoch,
environment: &str,
) -> Result<()> {
self.transaction(|tx| async move {
server::Entity::delete_many()
.filter(
Condition::all().add(
server::Column::Environment
.eq(environment)
.add(server::Column::Epoch.ne(new_epoch)),
),
)
.exec(&*tx)
.await?;
Ok(())
})
.await
}

View file

@ -351,6 +351,12 @@ impl Server {
}
}
}
app_state
.db
.delete_stale_servers(epoch, &app_state.config.zed_environment)
.await
.trace_err();
}
.instrument(span),
);