From 02733ecc8f49431c6645ca99632847839e5dc7fa Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 19 Nov 2022 14:40:39 -0600 Subject: [PATCH] jobs-sled: remove Stats --- jobs-sled/Cargo.toml | 2 +- jobs-sled/src/lib.rs | 46 +------------------------------------------- 2 files changed, 2 insertions(+), 46 deletions(-) diff --git a/jobs-sled/Cargo.toml b/jobs-sled/Cargo.toml index 156eeed..787578c 100644 --- a/jobs-sled/Cargo.toml +++ b/jobs-sled/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" [dependencies] actix-rt = "2.0.1" async-trait = "0.1.24" -background-jobs-core = { version = "0.13.0", path = "../jobs-core" } +background-jobs-core = { version = "0.14.0", path = "../jobs-core" } bincode = "1.2" sled = "0.34" serde_cbor = "0.11" diff --git a/jobs-sled/src/lib.rs b/jobs-sled/src/lib.rs index 7b23bc8..b92af41 100644 --- a/jobs-sled/src/lib.rs +++ b/jobs-sled/src/lib.rs @@ -17,7 +17,7 @@ use actix_rt::{ task::{spawn_blocking, JoinError}, time::timeout, }; -use background_jobs_core::{JobInfo, Stats}; +use background_jobs_core::JobInfo; use sled::{Db, Tree}; use std::{ collections::HashMap, @@ -54,7 +54,6 @@ pub struct Storage { running: Tree, running_inverse: Tree, queue: Tree, - stats: Tree, notifiers: Arc>>>, _db: Db, } @@ -259,48 +258,6 @@ impl background_jobs_core::Storage for Storage { }) .await??) } - - async fn get_stats(&self) -> Result { - let this = self.clone(); - - let stats = spawn_blocking(move || { - let stats = if let Some(stats_ivec) = this.stats.get("stats")? { - bincode::deserialize(&stats_ivec).unwrap_or_default() - } else { - Stats::default() - }; - - Ok(stats) as Result - }) - .await??; - - Ok(stats) - } - - async fn update_stats(&self, f: F) -> Result<()> - where - F: Fn(Stats) -> Stats + Send + 'static, - { - let this = self.clone(); - - Ok(spawn_blocking(move || { - this.stats.fetch_and_update("stats", move |opt| { - let stats = if let Some(stats_ivec) = opt { - bincode::deserialize(stats_ivec).unwrap_or_default() - } else { - Stats::default() - }; - - let new_stats = (f)(stats); - - let stats_vec = bincode::serialize(&new_stats).ok()?; - Some(stats_vec) - })?; - - Ok(()) as Result<()> - }) - .await??) - } } impl Storage { @@ -312,7 +269,6 @@ impl Storage { running: db.open_tree("background-jobs-running")?, running_inverse: db.open_tree("background-jobs-running-inverse")?, queue: db.open_tree("background-jobs-queue")?, - stats: db.open_tree("background-jobs-stats")?, notifiers: Arc::new(Mutex::new(HashMap::new())), _db: db, })