Update docs

This commit is contained in:
asonix 2020-04-20 19:42:39 -05:00
parent 759ccf018b
commit f8fa1bb5ef
5 changed files with 22 additions and 57 deletions

View file

@ -1,12 +1,12 @@
[package] [package]
name = "background-jobs" name = "background-jobs"
description = "Background Jobs implemented with sled, actix, and futures" description = "Background Jobs implemented with actix and futures"
version = "0.8.0-alpha.1" version = "0.8.0-alpha.1"
license-file = "LICENSE" license-file = "LICENSE"
authors = ["asonix <asonix@asonix.dog>"] authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/Aardwolf/background-jobs" repository = "https://git.asonix.dog/Aardwolf/background-jobs"
readme = "README.md" readme = "README.md"
keywords = ["jobs", "processor", "actix", "sled"] keywords = ["jobs", "processor", "actix"]
edition = "2018" edition = "2018"
[workspace] [workspace]
@ -18,7 +18,7 @@ members = [
] ]
[features] [features]
default = ["background-jobs-actix", "background-jobs-sled-storage"] default = ["background-jobs-actix"]
[dependencies.background-jobs-core] [dependencies.background-jobs-core]
version = "0.8.0-alpha.0" version = "0.8.0-alpha.0"
@ -28,8 +28,3 @@ path = "jobs-core"
version = "0.8.0-alpha.0" version = "0.8.0-alpha.0"
path = "jobs-actix" path = "jobs-actix"
optional = true optional = true
[dependencies.background-jobs-sled-storage]
version = "0.8.0-alpha.0"
path = "jobs-sled"
optional = true

View file

@ -13,13 +13,11 @@ might not be the best experience.
#### Add Background Jobs to your project #### Add Background Jobs to your project
```toml ```toml
[dependencies] [dependencies]
actix = "0.8" actix = "0.10.0-alpha.0"
background-jobs = "0.8.0-alpha.1" background-jobs = "0.8.0-alpha.1"
failure = "0.1" anyhow = "1.0"
futures = "0.1" futures = "0.3.4"
serde = "1.0" serde = { version = "1.0", features = ["derive"] }
serde_drive = "1.0"
sled = "0.29"
``` ```
#### To get started with Background Jobs, first you should define a job. #### To get started with Background Jobs, first you should define a job.
@ -28,10 +26,10 @@ operation. They implment the `Job`, `serde::Serialize`, and `serde::DeserializeO
```rust ```rust
use background_jobs::Job; use background_jobs::Job;
use failure::Error; use anyhow::Error;
use serde_derive::{Deserialize, Serialize}; use futures::future::{ok, Ready};
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct MyJob { pub struct MyJob {
some_usize: usize, some_usize: usize,
other_usize: usize, other_usize: usize,
@ -48,14 +46,14 @@ impl MyJob {
impl Job for MyJob { impl Job for MyJob {
type State = (); type State = ();
type Future = Result<(), Error>; type Future = Ready<Result<(), Error>>;
const NAME: &'static str = "MyJob"; const NAME: &'static str = "MyJob";
fn run(self, _: Self::State) -> Self::Future { fn run(self, _: Self::State) -> Self::Future {
info!("args: {:?}", self); info!("args: {:?}", self);
Ok(()) ok(())
} }
} }
``` ```
@ -83,7 +81,7 @@ impl MyState {
impl Job for MyJob { impl Job for MyJob {
type State = MyState; type State = MyState;
type Future = Result<(), Error>; type Future = Ready<Result<(), Error>>;
// The name of the job. It is super important that each job has a unique name, // The name of the job. It is super important that each job has a unique name,
// because otherwise one job will overwrite another job when they're being // because otherwise one job will overwrite another job when they're being
@ -111,7 +109,7 @@ impl Job for MyJob {
fn run(self, state: Self::State) -> Self::Future { fn run(self, state: Self::State) -> Self::Future {
info!("{}: args, {:?}", state.app_name, self); info!("{}: args, {:?}", state.app_name, self);
Ok(()) ok(())
} }
} }
``` ```
@ -123,17 +121,14 @@ spawning new jobs.
`background-jobs-actix` on it's own doesn't have a mechanism for storing worker state. This `background-jobs-actix` on it's own doesn't have a mechanism for storing worker state. This
can be implemented manually by implementing the `Storage` trait from `background-jobs-core`, can be implemented manually by implementing the `Storage` trait from `background-jobs-core`,
the in-memory store provided in the `background-jobs-core` crate can be used, or the or the provided in-memory store can be used.
`background-jobs-sled-storage` crate can be used to provide a
[Sled](https://github.com/spacejam/sled)-backed jobs store.
With that out of the way, back to the examples: With that out of the way, back to the examples:
##### Main ##### Main
```rust ```rust
use actix::System; use background_jobs::{create_server, WorkerConfig};
use background_jobs::{ServerConfig, WorkerConfig}; use anyhow::Error;
use failure::Error;
#[actix_rt::main] #[actix_rt::main]
async fn main() -> Result<(), Error> { async fn main() -> Result<(), Error> {
@ -143,14 +138,6 @@ async fn main() -> Result<(), Error> {
use background_jobs::memory_storage::Storage; use background_jobs::memory_storage::Storage;
let storage = Storage::new(); let storage = Storage::new();
/*
// Optionally, a storage backend using the Sled database is provided
use background_jobs::sled_storage::Storage;
use sled_extensions::Db;
let db = Db::open("my-sled-db")?;
let storage = Storage::new(db)?;
*/
// Start the application server. This guards access to to the jobs store // Start the application server. This guards access to to the jobs store
let queue_handle = create_server(storage); let queue_handle = create_server(storage);

View file

@ -14,5 +14,4 @@ async-trait = "0.1.24"
background-jobs = { version = "0.8.0-alpha.1", path = "../.." } background-jobs = { version = "0.8.0-alpha.1", path = "../.." }
env_logger = "0.7" env_logger = "0.7"
futures = "0.3" futures = "0.3"
sled-extensions = { version = "0.3.0-alpha.0", git = "https://git.asonix.dog/Aardwolf/sled-extensions" }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }

View file

@ -23,14 +23,6 @@ async fn main() -> Result<(), Error> {
use background_jobs::memory_storage::Storage; use background_jobs::memory_storage::Storage;
let storage = Storage::new(); let storage = Storage::new();
/*
// Optionally, a storage backend using the Sled database is provided
use background_jobs::sled_storage::Storage;
use sled_extensions::Db;
let db = Db::open("my-sled-db")?;
let storage = Storage::new(db)?;
*/
// Start the application server. This guards access to to the jobs store // Start the application server. This guards access to to the jobs store
let queue_handle = create_server(storage); let queue_handle = create_server(storage);

View file

@ -33,7 +33,6 @@
//! anyhow = "1.0" //! anyhow = "1.0"
//! futures = "0.1" //! futures = "0.1"
//! serde = { version = "1.0", features = ["derive"] } //! serde = { version = "1.0", features = ["derive"] }
//! sled = "0.28"
//! ``` //! ```
//! //!
//! #### To get started with Background Jobs, first you should define a job. //! #### To get started with Background Jobs, first you should define a job.
@ -83,6 +82,8 @@
//! //!
//! ```rust,ignore //! ```rust,ignore
//! use anyhow::Error; //! use anyhow::Error;
//! use background_jobs::Job;
//! use futures::future::{ok, Ready};
//! //!
//! #[derive(Clone, Debug)] //! #[derive(Clone, Debug)]
//! pub struct MyState { //! pub struct MyState {
@ -117,23 +118,19 @@
//! spawning new jobs. //! spawning new jobs.
//! //!
//! `background-jobs-actix` on it's own doesn't have a mechanism for storing worker state. This //! `background-jobs-actix` on it's own doesn't have a mechanism for storing worker state. This
//! can be implemented manually by implementing the `Storage` trait from `background-jobs-core`, //! can be implemented manually by implementing the `Storage` trait from `background-jobs-core`, or the provided in-memory store can be used.
//! or the `background-jobs-sled-storage` crate can be used to provide a
//! [Sled](https://github.com/spacejam/sled)-backed jobs store.
//! //!
//! With that out of the way, back to the examples: //! With that out of the way, back to the examples:
//! //!
//! ##### Main //! ##### Main
//! ```rust,ignore //! ```rust,ignore
//! use anyhow::Error; //! use anyhow::Error;
//! use background_jobs::{ServerConfig, sled_storage::Storage, WorkerConfig}; //! use background_jobs::{ServerConfig, memory_storage::Storage, WorkerConfig};
//! use sled::Db;
//! //!
//! #[actix_rt::main] //! #[actix_rt::main]
//! async fn main() -> Result<(), Error> { //! async fn main() -> Result<(), Error> {
//! // Set up our Storage //! // Set up our Storage
//! let db = Db::start_default("my-sled-db")?; //! let storage = Storage::new();
//! let storage = Storage::new(db)?;
//! //!
//! // Start the application server. This guards access to to the jobs store //! // Start the application server. This guards access to to the jobs store
//! let queue_handle = ServerConfig::new(storage).start(); //! let queue_handle = ServerConfig::new(storage).start();
@ -168,8 +165,3 @@ pub use background_jobs_core::{memory_storage, Backoff, Job, JobStat, MaxRetries
#[cfg(feature = "background-jobs-actix")] #[cfg(feature = "background-jobs-actix")]
pub use background_jobs_actix::{create_server, ActixJob, QueueHandle, WorkerConfig}; pub use background_jobs_actix::{create_server, ActixJob, QueueHandle, WorkerConfig};
#[cfg(feature = "background-jobs-sled-storage")]
pub mod sled_storage {
pub use background_jobs_sled_storage::{Error, SledStorage as Storage};
}