Files
nym/common/credential-proxy/src/storage/pruner.rs
T
Jędrzej Stuczyński d3cdaf373b Feature/credential proxy crate (#6018)
* moved storage and deposits buffer to the common lib

* move more of the state into the shared lib

* extracted the rest of the features into the shared lib

* fixed test imports

* clippy
2025-09-10 09:28:38 +01:00

39 lines
1.2 KiB
Rust

// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::storage::CredentialProxyStorage;
use tokio_util::sync::CancellationToken;
use tracing::{error, info};
pub struct StoragePruner {
cancellation_token: CancellationToken,
storage: CredentialProxyStorage,
}
impl StoragePruner {
pub fn new(cancellation_token: CancellationToken, storage: CredentialProxyStorage) -> Self {
Self {
cancellation_token,
storage,
}
}
pub async fn run_forever(self) {
info!("starting the storage pruner task");
loop {
tokio::select! {
biased;
_ = self.cancellation_token.cancelled() => {
break
}
_ = tokio::time::sleep(std::time::Duration::from_secs(60 * 60)) => {
match self.storage.prune_old_blinded_shares().await {
Ok(_res) => info!("🧹 Pruning old blinded shares complete"),
Err(err) => error!("Failed to prune old blinded shares: {err}"),
}
}
}
}
}
}