diff --git a/Cargo.toml b/Cargo.toml index 6e8eeac..830979e 100644 --- a/Cargo.toml +++ b/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 diff --git a/examples/actix-jobs-example/.env b/examples/actix-jobs-example/.env deleted file mode 100644 index 41e2ab9..0000000 --- a/examples/actix-jobs-example/.env +++ /dev/null @@ -1 +0,0 @@ -RUST_LOG=actix_jobs_example,jobs_actix=trace diff --git a/examples/actix-jobs-example/.gitignore b/examples/actix-jobs-example/.gitignore deleted file mode 100644 index ac25cf6..0000000 --- a/examples/actix-jobs-example/.gitignore +++ /dev/null @@ -1 +0,0 @@ -example-db diff --git a/examples/actix-jobs-example/Cargo.toml b/examples/actix-jobs-example/Cargo.toml deleted file mode 100644 index 51ecb5c..0000000 --- a/examples/actix-jobs-example/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "actix-jobs-example" -version = "0.1.0" -authors = ["asonix "] -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"] diff --git a/examples/actix-jobs-example/src/main.rs b/examples/actix-jobs-example/src/main.rs deleted file mode 100644 index a864b21..0000000 --- a/examples/actix-jobs-example/src/main.rs +++ /dev/null @@ -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 + 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(()) -} diff --git a/examples/server-jobs-example/Cargo.toml b/examples/server-jobs-example/Cargo.toml index 9d22b54..15bf15a 100644 --- a/examples/server-jobs-example/Cargo.toml +++ b/examples/server-jobs-example/Cargo.toml @@ -18,4 +18,4 @@ tokio = "0.1" version = "0.1" path = "../.." default-features = false -features = ["background-jobs-server-tokio"] +features = ["background-jobs-server"] diff --git a/examples/tokio-jobs-example/.env b/examples/tokio-jobs-example/.env deleted file mode 100644 index eb6e3b7..0000000 --- a/examples/tokio-jobs-example/.env +++ /dev/null @@ -1 +0,0 @@ -RUST_LOG=tokio_jobs_example,jobs_tokio=trace diff --git a/examples/tokio-jobs-example/.gitignore b/examples/tokio-jobs-example/.gitignore deleted file mode 100644 index ac25cf6..0000000 --- a/examples/tokio-jobs-example/.gitignore +++ /dev/null @@ -1 +0,0 @@ -example-db diff --git a/examples/tokio-jobs-example/Cargo.toml b/examples/tokio-jobs-example/Cargo.toml deleted file mode 100644 index 8c099f6..0000000 --- a/examples/tokio-jobs-example/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "tokio-jobs-example" -version = "0.1.0" -authors = ["asonix "] -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"] diff --git a/examples/tokio-jobs-example/src/main.rs b/examples/tokio-jobs-example/src/main.rs deleted file mode 100644 index 667b86f..0000000 --- a/examples/tokio-jobs-example/src/main.rs +++ /dev/null @@ -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 + 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(|_| ()) - })); -} diff --git a/jobs-server-tokio/Cargo.toml b/jobs-server/Cargo.toml similarity index 92% rename from jobs-server-tokio/Cargo.toml rename to jobs-server/Cargo.toml index 7a6a530..05ec9c9 100644 --- a/jobs-server-tokio/Cargo.toml +++ b/jobs-server/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "background-jobs-server-tokio" +name = "background-jobs-server" version = "0.1.0" authors = ["asonix "] edition = "2018" diff --git a/jobs-server-tokio/LICENSE b/jobs-server/LICENSE similarity index 100% rename from jobs-server-tokio/LICENSE rename to jobs-server/LICENSE diff --git a/jobs-server-tokio/src/lib.rs b/jobs-server/src/lib.rs similarity index 100% rename from jobs-server-tokio/src/lib.rs rename to jobs-server/src/lib.rs diff --git a/jobs-server-tokio/src/server/mod.rs b/jobs-server/src/server/mod.rs similarity index 100% rename from jobs-server-tokio/src/server/mod.rs rename to jobs-server/src/server/mod.rs diff --git a/jobs-server-tokio/src/server/portmap.rs b/jobs-server/src/server/portmap.rs similarity index 100% rename from jobs-server-tokio/src/server/portmap.rs rename to jobs-server/src/server/portmap.rs diff --git a/jobs-server-tokio/src/server/pull.rs b/jobs-server/src/server/pull.rs similarity index 100% rename from jobs-server-tokio/src/server/pull.rs rename to jobs-server/src/server/pull.rs diff --git a/jobs-server-tokio/src/server/push.rs b/jobs-server/src/server/push.rs similarity index 100% rename from jobs-server-tokio/src/server/push.rs rename to jobs-server/src/server/push.rs diff --git a/jobs-server-tokio/src/server/stalled.rs b/jobs-server/src/server/stalled.rs similarity index 100% rename from jobs-server-tokio/src/server/stalled.rs rename to jobs-server/src/server/stalled.rs diff --git a/jobs-server-tokio/src/spawner.rs b/jobs-server/src/spawner.rs similarity index 100% rename from jobs-server-tokio/src/spawner.rs rename to jobs-server/src/spawner.rs diff --git a/jobs-server-tokio/src/worker/config.rs b/jobs-server/src/worker/config.rs similarity index 100% rename from jobs-server-tokio/src/worker/config.rs rename to jobs-server/src/worker/config.rs diff --git a/jobs-server-tokio/src/worker/mod.rs b/jobs-server/src/worker/mod.rs similarity index 100% rename from jobs-server-tokio/src/worker/mod.rs rename to jobs-server/src/worker/mod.rs diff --git a/jobs-server-tokio/src/worker/portmap.rs b/jobs-server/src/worker/portmap.rs similarity index 100% rename from jobs-server-tokio/src/worker/portmap.rs rename to jobs-server/src/worker/portmap.rs diff --git a/src/lib.rs b/src/lib.rs index e47f700..8c3ceb6 100644 --- a/src/lib.rs +++ b/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};