Delete actix and tokio examples

This commit is contained in:
asonix 2018-11-17 16:59:16 -06:00
parent c8f1f6cd34
commit 6ae02e08cb
23 changed files with 8 additions and 229 deletions

View file

@ -8,31 +8,19 @@ edition = "2018"
members = [ members = [
"jobs-actix", "jobs-actix",
"jobs-core", "jobs-core",
"jobs-server-tokio", "jobs-server",
"jobs-tokio", "jobs-tokio",
"examples/actix-jobs-example",
"examples/server-jobs-example", "examples/server-jobs-example",
"examples/tokio-jobs-example",
] ]
[features] [features]
default = ["background-jobs-actix", "background-jobs-server-tokio", "background-jobs-server-tokio/tokio-zmq", "background-jobs-tokio"] default = ["background-jobs-server", "background-jobs-server/tokio-zmq"]
[dependencies.background-jobs-actix]
version = "0.1"
path = "jobs-actix"
optional = true
[dependencies.background-jobs-core] [dependencies.background-jobs-core]
version = "0.1" version = "0.1"
path = "jobs-core" path = "jobs-core"
[dependencies.background-jobs-server-tokio] [dependencies.background-jobs-server]
version = "0.1" version = "0.1"
path = "jobs-server-tokio" path = "jobs-server"
optional = true
[dependencies.background-jobs-tokio]
version = "0.1"
path = "jobs-tokio"
optional = true optional = true

View file

@ -1 +0,0 @@
RUST_LOG=actix_jobs_example,jobs_actix=trace

View file

@ -1 +0,0 @@
example-db

View file

@ -1,21 +0,0 @@
[package]
name = "actix-jobs-example"
version = "0.1.0"
authors = ["asonix <asonix@asonix.dog>"]
edition = "2018"
[dependencies]
actix = "0.7"
dotenv = "0.13"
env_logger = "0.5"
failure = "0.1"
futures = "0.1"
log = "0.4"
serde = "1.0"
serde_derive = "1.0"
[dependencies.background-jobs]
version = "0.1"
path = "../.."
default-features = false
features = ["background-jobs-actix"]

View file

@ -1,73 +0,0 @@
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
use background_jobs::{Backoff, JobsBuilder, MaxRetries, Processor, QueueJob};
use failure::Error;
use futures::{future::IntoFuture, Future};
#[derive(Clone, Debug, Deserialize, Serialize)]
struct MyJobArguments {
some_usize: usize,
other_usize: usize,
}
#[derive(Clone, Debug)]
struct MyProcessor;
impl Processor for MyProcessor {
type Arguments = MyJobArguments;
fn name() -> &'static str {
"MyProcessor"
}
fn queue() -> &'static str {
"default"
}
fn max_retries() -> MaxRetries {
MaxRetries::Count(1)
}
fn backoff_strategy() -> Backoff {
Backoff::Exponential(2)
}
fn process(&self, args: Self::Arguments) -> Box<dyn Future<Item = (), Error = Error> + Send> {
info!("args: {:?}", args);
Box::new(Ok(()).into_future())
}
}
fn main() -> Result<(), Error> {
dotenv::dotenv().ok();
env_logger::init();
let sys = actix::System::new("jobs-system");
let mut builder = JobsBuilder::new(1234, 4, "example-db");
builder.register_processor(MyProcessor);
let jobs_actor = builder.build()?;
let (_, _, jobs) = (1..18).fold((0, 1, Vec::new()), |(x, y, mut acc), _| {
acc.push(MyJobArguments {
some_usize: x,
other_usize: y,
});
(y, x + y, acc)
});
for job in jobs {
jobs_actor.do_send(QueueJob(MyProcessor::new_job(job, None, None)?));
}
let _ = sys.run();
Ok(())
}

View file

@ -18,4 +18,4 @@ tokio = "0.1"
version = "0.1" version = "0.1"
path = "../.." path = "../.."
default-features = false default-features = false
features = ["background-jobs-server-tokio"] features = ["background-jobs-server"]

View file

@ -1 +0,0 @@
RUST_LOG=tokio_jobs_example,jobs_tokio=trace

View file

@ -1 +0,0 @@
example-db

View file

@ -1,21 +0,0 @@
[package]
name = "tokio-jobs-example"
version = "0.1.0"
authors = ["asonix <asonix@asonix.dog>"]
edition = "2018"
[dependencies]
dotenv = "0.13"
env_logger = "0.5"
failure = "0.1"
futures = "0.1"
log = "0.4"
serde = "1.0"
serde_derive = "1.0"
tokio = "0.1"
[dependencies.background-jobs]
version = "0.1"
path = "../.."
default-features = false
features = ["background-jobs-tokio"]

View file

@ -1,84 +0,0 @@
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
use std::time::Duration;
use background_jobs::{Backoff, JobRunner, MaxRetries, Processor};
use failure::Error;
use futures::{
future::{lazy, IntoFuture},
Future,
};
#[derive(Clone, Debug, Deserialize, Serialize)]
struct MyJobArguments {
some_usize: usize,
other_usize: usize,
}
#[derive(Clone, Debug)]
struct MyProcessor;
impl Processor for MyProcessor {
type Arguments = MyJobArguments;
fn name() -> &'static str {
"MyProcessor"
}
fn queue() -> &'static str {
"default"
}
fn max_retries() -> MaxRetries {
MaxRetries::Count(1)
}
fn backoff_strategy() -> Backoff {
Backoff::Exponential(2)
}
fn process(&self, args: Self::Arguments) -> Box<dyn Future<Item = (), Error = Error> + Send> {
info!("args: {:?}", args);
Box::new(Ok(()).into_future())
}
}
fn main() {
dotenv::dotenv().ok();
env_logger::init();
let (_, _, jobs) = (1..18).fold((0, 1, Vec::new()), |(x, y, mut acc), _| {
acc.push(MyJobArguments {
some_usize: x,
other_usize: y,
});
(y, x + y, acc)
});
tokio::run(lazy(move || {
let mut runner = JobRunner::new(1234, 4, "example-db");
runner.register_processor(MyProcessor);
let handle = runner.spawn();
for job in jobs {
tokio::spawn(
handle
.queue(MyProcessor::new_job(job, None, None).unwrap())
.then(|_| Ok(())),
);
}
tokio::timer::Delay::new(tokio::clock::now() + Duration::from_secs(1))
.map(move |_| {
let _ = handle;
()
})
.map_err(|_| ())
}));
}

View file

@ -1,5 +1,5 @@
[package] [package]
name = "background-jobs-server-tokio" name = "background-jobs-server"
version = "0.1.0" version = "0.1.0"
authors = ["asonix <asonix@asonix.dog>"] authors = ["asonix <asonix@asonix.dog>"]
edition = "2018" edition = "2018"

View file

@ -2,11 +2,5 @@ pub use background_jobs_core::{
Backoff, JobError, JobInfo, JobStatus, MaxRetries, Processor, Processors, ShouldStop, Storage, Backoff, JobError, JobInfo, JobStatus, MaxRetries, Processor, Processors, ShouldStop, Storage,
}; };
#[cfg(feature = "background-jobs-tokio")] #[cfg(feature = "background-jobs-server")]
pub use background_jobs_tokio::{JobRunner, ProcessorHandle}; pub use background_jobs_server::{ServerConfig, SpawnerConfig, WorkerConfig};
#[cfg(feature = "background-jobs-actix")]
pub use background_jobs_actix::{JobsActor, JobsBuilder, QueueJob};
#[cfg(feature = "background-jobs-server-tokio")]
pub use background_jobs_server_tokio::{ServerConfig, SpawnerConfig, WorkerConfig};