diff --git a/Cargo.toml b/Cargo.toml index abfe097..b5e765c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,6 @@ path = "jobs-actix" optional = true [dependencies.background-jobs-sled-storage] -version = "0.1.3" +version = "0.2.0" path = "jobs-sled" optional = true diff --git a/examples/actix-example/src/main.rs b/examples/actix-example/src/main.rs index 5c26657..5fbfda1 100644 --- a/examples/actix-example/src/main.rs +++ b/examples/actix-example/src/main.rs @@ -1,7 +1,6 @@ use actix::System; use background_jobs::{Backoff, Job, MaxRetries, Processor, ServerConfig, WorkerConfig}; use failure::Error; -use futures::{future::ok, Future}; use serde_derive::{Deserialize, Serialize}; const DEFAULT_QUEUE: &'static str = "default"; @@ -76,11 +75,12 @@ impl MyJob { impl Job for MyJob { type Processor = MyProcessor; type State = MyState; + type Future = Result<(), Error>; - fn run(self, state: MyState) -> Box + Send> { + fn run(self, state: MyState) -> Self::Future { println!("{}: args, {:?}", state.app_name, self); - Box::new(ok(())) + Ok(()) } } diff --git a/jobs-sled/Cargo.toml b/jobs-sled/Cargo.toml index 20d7c1f..55741cc 100644 --- a/jobs-sled/Cargo.toml +++ b/jobs-sled/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "background-jobs-sled-storage" description = "Sled storage backend for background-jobs" -version = "0.1.3" +version = "0.2.0" license-file = "../LICENSE" authors = ["asonix "] repository = "https://git.asonix.dog/Aardwolf/background-jobs" diff --git a/jobs-sled/src/lib.rs b/jobs-sled/src/lib.rs index d2c84ce..54cc014 100644 --- a/jobs-sled/src/lib.rs +++ b/jobs-sled/src/lib.rs @@ -1,3 +1,18 @@ +#![deny(missing_docs)] + +//! # Background Jobs Sled Storage +//! _An implementation of the Background Jobs Storage trait based on the Sled embedded database_ +//! +//! ### Usage +//! ```rust +//! use background_jobs::{ServerConfig, sled_storage::Storage}; +//! use sled_extensions::{ConfigBuilder, Db}; +//! +//! let db = Db::start(ConfigBuilder::default().temporary(true).build())?; +//! let storage = Storagege::new(db)?; +//! let queue_handle = ServerConfig::new(storage).thread_count(8).start(); +//! ``` + use background_jobs_core::{JobInfo, Stats, Storage}; use chrono::offset::Utc; use sled_extensions::{bincode::Tree, cbor, Db, DbExt}; @@ -5,6 +20,7 @@ use sled_extensions::{bincode::Tree, cbor, Db, DbExt}; pub use sled_extensions::{Error, Result}; #[derive(Clone)] +/// The Sled-backed storage implementation pub struct SledStorage { jobinfo: cbor::Tree, running: Tree, @@ -108,6 +124,7 @@ impl Storage for SledStorage { } impl SledStorage { + /// Create a new Storage struct pub fn new(db: Db) -> Result { Ok(SledStorage { jobinfo: db.open_cbor_tree("background-jobs-jobinfo")?,