mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-22 03:51:00 +00:00
Prepare jobs-sled for release
This commit is contained in:
parent
7e06ad981f
commit
a5b2a3e8dd
4 changed files with 22 additions and 5 deletions
|
@ -30,6 +30,6 @@ path = "jobs-actix"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies.background-jobs-sled-storage]
|
[dependencies.background-jobs-sled-storage]
|
||||||
version = "0.1.3"
|
version = "0.2.0"
|
||||||
path = "jobs-sled"
|
path = "jobs-sled"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use actix::System;
|
use actix::System;
|
||||||
use background_jobs::{Backoff, Job, MaxRetries, Processor, ServerConfig, WorkerConfig};
|
use background_jobs::{Backoff, Job, MaxRetries, Processor, ServerConfig, WorkerConfig};
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use futures::{future::ok, Future};
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
const DEFAULT_QUEUE: &'static str = "default";
|
const DEFAULT_QUEUE: &'static str = "default";
|
||||||
|
@ -76,11 +75,12 @@ impl MyJob {
|
||||||
impl Job for MyJob {
|
impl Job for MyJob {
|
||||||
type Processor = MyProcessor;
|
type Processor = MyProcessor;
|
||||||
type State = MyState;
|
type State = MyState;
|
||||||
|
type Future = Result<(), Error>;
|
||||||
|
|
||||||
fn run(self, state: MyState) -> Box<dyn Future<Item = (), Error = Error> + Send> {
|
fn run(self, state: MyState) -> Self::Future {
|
||||||
println!("{}: args, {:?}", state.app_name, self);
|
println!("{}: args, {:?}", state.app_name, self);
|
||||||
|
|
||||||
Box::new(ok(()))
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "background-jobs-sled-storage"
|
name = "background-jobs-sled-storage"
|
||||||
description = "Sled storage backend for background-jobs"
|
description = "Sled storage backend for background-jobs"
|
||||||
version = "0.1.3"
|
version = "0.2.0"
|
||||||
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"
|
||||||
|
|
|
@ -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 background_jobs_core::{JobInfo, Stats, Storage};
|
||||||
use chrono::offset::Utc;
|
use chrono::offset::Utc;
|
||||||
use sled_extensions::{bincode::Tree, cbor, Db, DbExt};
|
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};
|
pub use sled_extensions::{Error, Result};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
/// The Sled-backed storage implementation
|
||||||
pub struct SledStorage {
|
pub struct SledStorage {
|
||||||
jobinfo: cbor::Tree<JobInfo>,
|
jobinfo: cbor::Tree<JobInfo>,
|
||||||
running: Tree<u64>,
|
running: Tree<u64>,
|
||||||
|
@ -108,6 +124,7 @@ impl Storage for SledStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SledStorage {
|
impl SledStorage {
|
||||||
|
/// Create a new Storage struct
|
||||||
pub fn new(db: Db) -> Result<Self> {
|
pub fn new(db: Db) -> Result<Self> {
|
||||||
Ok(SledStorage {
|
Ok(SledStorage {
|
||||||
jobinfo: db.open_cbor_tree("background-jobs-jobinfo")?,
|
jobinfo: db.open_cbor_tree("background-jobs-jobinfo")?,
|
||||||
|
|
Loading…
Reference in a new issue