mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-21 19:40:59 +00:00
Delete actix and tokio examples
This commit is contained in:
parent
c8f1f6cd34
commit
6ae02e08cb
23 changed files with 8 additions and 229 deletions
20
Cargo.toml
20
Cargo.toml
|
@ -8,31 +8,19 @@ edition = "2018"
|
|||
members = [
|
||||
"jobs-actix",
|
||||
"jobs-core",
|
||||
"jobs-server-tokio",
|
||||
"jobs-server",
|
||||
"jobs-tokio",
|
||||
"examples/actix-jobs-example",
|
||||
"examples/server-jobs-example",
|
||||
"examples/tokio-jobs-example",
|
||||
]
|
||||
|
||||
[features]
|
||||
default = ["background-jobs-actix", "background-jobs-server-tokio", "background-jobs-server-tokio/tokio-zmq", "background-jobs-tokio"]
|
||||
|
||||
[dependencies.background-jobs-actix]
|
||||
version = "0.1"
|
||||
path = "jobs-actix"
|
||||
optional = true
|
||||
default = ["background-jobs-server", "background-jobs-server/tokio-zmq"]
|
||||
|
||||
[dependencies.background-jobs-core]
|
||||
version = "0.1"
|
||||
path = "jobs-core"
|
||||
|
||||
[dependencies.background-jobs-server-tokio]
|
||||
[dependencies.background-jobs-server]
|
||||
version = "0.1"
|
||||
path = "jobs-server-tokio"
|
||||
optional = true
|
||||
|
||||
[dependencies.background-jobs-tokio]
|
||||
version = "0.1"
|
||||
path = "jobs-tokio"
|
||||
path = "jobs-server"
|
||||
optional = true
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
RUST_LOG=actix_jobs_example,jobs_actix=trace
|
1
examples/actix-jobs-example/.gitignore
vendored
1
examples/actix-jobs-example/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
example-db
|
|
@ -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"]
|
|
@ -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(())
|
||||
}
|
|
@ -18,4 +18,4 @@ tokio = "0.1"
|
|||
version = "0.1"
|
||||
path = "../.."
|
||||
default-features = false
|
||||
features = ["background-jobs-server-tokio"]
|
||||
features = ["background-jobs-server"]
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
RUST_LOG=tokio_jobs_example,jobs_tokio=trace
|
1
examples/tokio-jobs-example/.gitignore
vendored
1
examples/tokio-jobs-example/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
example-db
|
|
@ -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"]
|
|
@ -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(|_| ())
|
||||
}));
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "background-jobs-server-tokio"
|
||||
name = "background-jobs-server"
|
||||
version = "0.1.0"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
edition = "2018"
|
10
src/lib.rs
10
src/lib.rs
|
@ -2,11 +2,5 @@ pub use background_jobs_core::{
|
|||
Backoff, JobError, JobInfo, JobStatus, MaxRetries, Processor, Processors, ShouldStop, Storage,
|
||||
};
|
||||
|
||||
#[cfg(feature = "background-jobs-tokio")]
|
||||
pub use background_jobs_tokio::{JobRunner, ProcessorHandle};
|
||||
|
||||
#[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};
|
||||
#[cfg(feature = "background-jobs-server")]
|
||||
pub use background_jobs_server::{ServerConfig, SpawnerConfig, WorkerConfig};
|
||||
|
|
Loading…
Reference in a new issue