mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-25 13:30:59 +00:00
Use stable sled-extensions
This commit is contained in:
parent
7a365ad415
commit
b017803b74
6 changed files with 18 additions and 10 deletions
|
@ -11,6 +11,6 @@ actix = "0.8"
|
||||||
background-jobs = { version = "0.6.0", path = "../.." }
|
background-jobs = { version = "0.6.0", path = "../.." }
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
sled-extensions = { version = "0.1.0", git = "https://git.asonix.dog/asonix/sled-extensions" }
|
sled-extensions = "0.1.0"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
|
|
|
@ -28,6 +28,7 @@ pub struct ServerConfig<S> {
|
||||||
impl<S> ServerConfig<S>
|
impl<S> ServerConfig<S>
|
||||||
where
|
where
|
||||||
S: Storage + Sync + 'static,
|
S: Storage + Sync + 'static,
|
||||||
|
S::Error: Send + Sync,
|
||||||
{
|
{
|
||||||
/// Create a new ServerConfig
|
/// Create a new ServerConfig
|
||||||
pub fn new(storage: S) -> Self {
|
pub fn new(storage: S) -> Self {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use background_jobs_core::{JobInfo, NewJobInfo, ReturnJobInfo, Stats, Storage};
|
use background_jobs_core::{JobInfo, NewJobInfo, ReturnJobInfo, Stats, Storage};
|
||||||
use failure::{Error, Fail};
|
use failure::Error;
|
||||||
|
|
||||||
pub(crate) trait ActixStorage {
|
pub(crate) trait ActixStorage {
|
||||||
fn new_job(&mut self, job: NewJobInfo) -> Result<u64, Error>;
|
fn new_job(&mut self, job: NewJobInfo) -> Result<u64, Error>;
|
||||||
|
@ -14,12 +14,14 @@ pub(crate) trait ActixStorage {
|
||||||
pub(crate) struct StorageWrapper<S, E>(pub(crate) S)
|
pub(crate) struct StorageWrapper<S, E>(pub(crate) S)
|
||||||
where
|
where
|
||||||
S: Storage<Error = E>,
|
S: Storage<Error = E>,
|
||||||
E: Fail;
|
S::Error: Send,
|
||||||
|
E: std::error::Error + Send;
|
||||||
|
|
||||||
impl<S, E> ActixStorage for StorageWrapper<S, E>
|
impl<S, E> ActixStorage for StorageWrapper<S, E>
|
||||||
where
|
where
|
||||||
S: Storage<Error = E>,
|
S: Storage<Error = E>,
|
||||||
E: Fail,
|
S::Error: Send,
|
||||||
|
E: std::error::Error + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
fn new_job(&mut self, job: NewJobInfo) -> Result<u64, Error> {
|
fn new_job(&mut self, job: NewJobInfo) -> Result<u64, Error> {
|
||||||
self.0.new_job(job).map_err(Error::from)
|
self.0.new_job(job).map_err(Error::from)
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use chrono::offset::Utc;
|
use chrono::offset::Utc;
|
||||||
use failure::Fail;
|
|
||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
use crate::{JobInfo, NewJobInfo, ReturnJobInfo, Stats};
|
use crate::{JobInfo, NewJobInfo, ReturnJobInfo, Stats};
|
||||||
|
@ -31,7 +30,7 @@ use crate::{JobInfo, NewJobInfo, ReturnJobInfo, Stats};
|
||||||
/// the `background-jobs-sled-storage` crate.
|
/// the `background-jobs-sled-storage` crate.
|
||||||
pub trait Storage: Clone + Send {
|
pub trait Storage: Clone + Send {
|
||||||
/// The error type used by the storage mechansim.
|
/// The error type used by the storage mechansim.
|
||||||
type Error: Fail;
|
type Error: std::error::Error;
|
||||||
|
|
||||||
/// This method generates unique IDs for jobs
|
/// This method generates unique IDs for jobs
|
||||||
fn generate_id(&mut self) -> Result<u64, Self::Error>;
|
fn generate_id(&mut self) -> Result<u64, Self::Error>;
|
||||||
|
@ -265,7 +264,7 @@ pub mod memory_storage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Fail)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Never {}
|
pub enum Never {}
|
||||||
|
|
||||||
impl fmt::Display for Never {
|
impl fmt::Display for Never {
|
||||||
|
@ -274,6 +273,12 @@ pub mod memory_storage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for Never {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
match *self {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Fail)]
|
#[derive(Clone, Debug, Fail)]
|
||||||
#[fail(display = "Created too many storages, can't generate any more IDs")]
|
#[fail(display = "Created too many storages, can't generate any more IDs")]
|
||||||
pub struct TooManyStoragesError;
|
pub struct TooManyStoragesError;
|
||||||
|
|
|
@ -13,4 +13,4 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
background-jobs-core = { version = "0.6", path = "../jobs-core" }
|
background-jobs-core = { version = "0.6", path = "../jobs-core" }
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
sled-extensions = { version = "0.1", git = "https://git.asonix.dog/asonix/sled-extensions", features = ["bincode", "cbor"] }
|
sled-extensions = { version = "0.1", features = ["bincode", "cbor"] }
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use background_jobs_core::{JobInfo, Stats, Storage};
|
use background_jobs_core::{JobInfo, Stats, Storage};
|
||||||
use chrono::offset::Utc;
|
use chrono::offset::Utc;
|
||||||
use sled_extensions::{structured::{cbor, bincode::Tree}, Db, DbExt};
|
use sled_extensions::{bincode::Tree, cbor, Db, DbExt};
|
||||||
|
|
||||||
pub use sled_extensions::error::{Result, Error};
|
pub use sled_extensions::{Error, Result};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SledStorage {
|
pub struct SledStorage {
|
||||||
|
|
Loading…
Reference in a new issue