mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 01:11:10 +00:00
Improve storage monitor API (#2899)
This removes the need to unnecessarily provide a very specific data structure `DatabaseSource` and removes huge `sc-client-db` dependency from storage monitor. It is now possible to use storage monitor with any path. P.S. I still strongly dislike that it pulls `clap` dependency for such a small feature, but many other crates do as well, so nothing special here.
This commit is contained in:
@@ -15,7 +15,6 @@ workspace = true
|
||||
clap = { version = "4.4.14", features = ["derive", "string"] }
|
||||
log = "0.4.17"
|
||||
fs4 = "0.7.0"
|
||||
sc-client-db = { path = "../db", default-features = false }
|
||||
sp-core = { path = "../../primitives/core" }
|
||||
tokio = "1.22.0"
|
||||
tokio = { version = "1.22.0", features = ["time"] }
|
||||
thiserror = "1.0.48"
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use clap::Args;
|
||||
use sc_client_db::DatabaseSource;
|
||||
use sp_core::traits::SpawnEssentialNamed;
|
||||
use std::{
|
||||
io,
|
||||
@@ -70,43 +69,37 @@ impl StorageMonitorService {
|
||||
/// Creates new StorageMonitorService for given client config
|
||||
pub fn try_spawn(
|
||||
parameters: StorageMonitorParams,
|
||||
database: DatabaseSource,
|
||||
path: PathBuf,
|
||||
spawner: &impl SpawnEssentialNamed,
|
||||
) -> Result<()> {
|
||||
Ok(match (parameters.threshold, database.path()) {
|
||||
(0, _) => {
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"StorageMonitorService: threshold `0` given, storage monitoring disabled",
|
||||
);
|
||||
},
|
||||
(_, None) => {
|
||||
log::warn!(
|
||||
target: LOG_TARGET,
|
||||
"StorageMonitorService: no database path to observe",
|
||||
);
|
||||
},
|
||||
(threshold, Some(path)) => {
|
||||
log::debug!(
|
||||
target: LOG_TARGET,
|
||||
"Initializing StorageMonitorService for db path: {path:?}",
|
||||
);
|
||||
if parameters.threshold == 0 {
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"StorageMonitorService: threshold `0` given, storage monitoring disabled",
|
||||
);
|
||||
} else {
|
||||
log::debug!(
|
||||
target: LOG_TARGET,
|
||||
"Initializing StorageMonitorService for db path: {}",
|
||||
path.display()
|
||||
);
|
||||
|
||||
Self::check_free_space(&path, threshold)?;
|
||||
Self::check_free_space(&path, parameters.threshold)?;
|
||||
|
||||
let storage_monitor_service = StorageMonitorService {
|
||||
path: path.to_path_buf(),
|
||||
threshold,
|
||||
polling_period: Duration::from_secs(parameters.polling_period.into()),
|
||||
};
|
||||
let storage_monitor_service = StorageMonitorService {
|
||||
path,
|
||||
threshold: parameters.threshold,
|
||||
polling_period: Duration::from_secs(parameters.polling_period.into()),
|
||||
};
|
||||
|
||||
spawner.spawn_essential(
|
||||
"storage-monitor",
|
||||
None,
|
||||
Box::pin(storage_monitor_service.run()),
|
||||
);
|
||||
},
|
||||
})
|
||||
spawner.spawn_essential(
|
||||
"storage-monitor",
|
||||
None,
|
||||
Box::pin(storage_monitor_service.run()),
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Main monitoring loop, intended to be spawned as essential task. Quits if free space drop
|
||||
|
||||
Reference in New Issue
Block a user