mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-25 13:30:59 +00:00
jobs-sled: remove Stats
This commit is contained in:
parent
3c34d66e48
commit
02733ecc8f
2 changed files with 2 additions and 46 deletions
|
@ -13,7 +13,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-rt = "2.0.1"
|
actix-rt = "2.0.1"
|
||||||
async-trait = "0.1.24"
|
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"
|
bincode = "1.2"
|
||||||
sled = "0.34"
|
sled = "0.34"
|
||||||
serde_cbor = "0.11"
|
serde_cbor = "0.11"
|
||||||
|
|
|
@ -17,7 +17,7 @@ use actix_rt::{
|
||||||
task::{spawn_blocking, JoinError},
|
task::{spawn_blocking, JoinError},
|
||||||
time::timeout,
|
time::timeout,
|
||||||
};
|
};
|
||||||
use background_jobs_core::{JobInfo, Stats};
|
use background_jobs_core::JobInfo;
|
||||||
use sled::{Db, Tree};
|
use sled::{Db, Tree};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
@ -54,7 +54,6 @@ pub struct Storage {
|
||||||
running: Tree,
|
running: Tree,
|
||||||
running_inverse: Tree,
|
running_inverse: Tree,
|
||||||
queue: Tree,
|
queue: Tree,
|
||||||
stats: Tree,
|
|
||||||
notifiers: Arc<Mutex<HashMap<String, Arc<Notify>>>>,
|
notifiers: Arc<Mutex<HashMap<String, Arc<Notify>>>>,
|
||||||
_db: Db,
|
_db: Db,
|
||||||
}
|
}
|
||||||
|
@ -259,48 +258,6 @@ impl background_jobs_core::Storage for Storage {
|
||||||
})
|
})
|
||||||
.await??)
|
.await??)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_stats(&self) -> Result<Stats> {
|
|
||||||
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<Stats>
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
|
|
||||||
Ok(stats)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn update_stats<F>(&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 {
|
impl Storage {
|
||||||
|
@ -312,7 +269,6 @@ impl Storage {
|
||||||
running: db.open_tree("background-jobs-running")?,
|
running: db.open_tree("background-jobs-running")?,
|
||||||
running_inverse: db.open_tree("background-jobs-running-inverse")?,
|
running_inverse: db.open_tree("background-jobs-running-inverse")?,
|
||||||
queue: db.open_tree("background-jobs-queue")?,
|
queue: db.open_tree("background-jobs-queue")?,
|
||||||
stats: db.open_tree("background-jobs-stats")?,
|
|
||||||
notifiers: Arc::new(Mutex::new(HashMap::new())),
|
notifiers: Arc::new(Mutex::new(HashMap::new())),
|
||||||
_db: db,
|
_db: db,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue