mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-21 19:40:59 +00:00
Update tokio-zmq, optionally use futures-zmq instead
This commit is contained in:
parent
a877b5c9e8
commit
960c0235c4
13 changed files with 126 additions and 109 deletions
|
@ -16,7 +16,7 @@ members = [
|
|||
]
|
||||
|
||||
[features]
|
||||
default = ["jobs-actix", "jobs-server-tokio", "jobs-tokio"]
|
||||
default = ["jobs-actix", "jobs-server-tokio", "jobs-server-tokio/tokio-zmq", "jobs-tokio"]
|
||||
|
||||
[dependencies.jobs-actix]
|
||||
version = "0.1"
|
||||
|
|
|
@ -1 +1 @@
|
|||
RUST_LOG=info
|
||||
RUST_LOG=server_jobs_example=info
|
||||
|
|
|
@ -12,9 +12,19 @@ serde = "1.0"
|
|||
serde_json = "1.0"
|
||||
tokio = "0.1"
|
||||
tokio-threadpool = "0.1"
|
||||
tokio-zmq = "0.6.1"
|
||||
zmq = "0.8"
|
||||
|
||||
[features]
|
||||
default = ["tokio-zmq"]
|
||||
|
||||
[dependencies.jobs-core]
|
||||
version = "0.1"
|
||||
path = "../jobs-core"
|
||||
|
||||
[dependencies.tokio-zmq]
|
||||
version = "0.8"
|
||||
optional = true
|
||||
|
||||
[dependencies.futures-zmq]
|
||||
version = "0.3"
|
||||
optional = true
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
#[macro_use]
|
||||
extern crate failure;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use failure::Error;
|
||||
|
||||
mod server;
|
||||
|
|
|
@ -4,9 +4,10 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
|
||||
use failure::Error;
|
||||
use failure::{Error, Fail};
|
||||
use futures::{future::poll_fn, Future};
|
||||
use jobs_core::Storage;
|
||||
use log::{error, info};
|
||||
use tokio_threadpool::blocking;
|
||||
use zmq::Context;
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
use std::{collections::BTreeMap, sync::Arc, time::Duration};
|
||||
|
||||
use failure::Error;
|
||||
use futures::{future::lazy, Future, Stream};
|
||||
use futures::{Future, Stream};
|
||||
#[cfg(feature = "futures-zmq")]
|
||||
use futures_zmq::{prelude::*, Multipart, Rep};
|
||||
use log::{error, info};
|
||||
use tokio::timer::Delay;
|
||||
#[cfg(feature = "tokio-zmq")]
|
||||
use tokio_zmq::{prelude::*, Multipart, Rep};
|
||||
use zmq::Message;
|
||||
|
||||
|
@ -85,11 +89,10 @@ impl ResetPortMapConfig {
|
|||
}
|
||||
|
||||
fn build(self) -> impl Future<Item = (), Error = Error> {
|
||||
lazy(|| {
|
||||
let rep = Rep::builder(self.config.context.clone())
|
||||
Rep::builder(self.config.context.clone())
|
||||
.bind(&self.address)
|
||||
.build()?;
|
||||
|
||||
.build()
|
||||
.map(|rep| {
|
||||
let config = PortMapConfig {
|
||||
rep,
|
||||
address: self.address,
|
||||
|
@ -98,8 +101,7 @@ impl ResetPortMapConfig {
|
|||
};
|
||||
|
||||
tokio::spawn(config.run());
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.from_err()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use failure::Error;
|
||||
use futures::{
|
||||
future::{lazy, poll_fn},
|
||||
Future, Stream,
|
||||
};
|
||||
use failure::{Error, Fail};
|
||||
use futures::{future::poll_fn, Future, Stream};
|
||||
#[cfg(feature = "futures-zmq")]
|
||||
use futures_zmq::{prelude::*, Multipart, Pull};
|
||||
use jobs_core::{JobInfo, Storage};
|
||||
use log::{error, info, trace};
|
||||
use tokio::timer::Delay;
|
||||
use tokio_threadpool::blocking;
|
||||
#[cfg(feature = "tokio-zmq")]
|
||||
use tokio_zmq::{prelude::*, Multipart, Pull};
|
||||
|
||||
use crate::server::{coerce, Config};
|
||||
|
@ -112,11 +113,10 @@ impl ResetPullConfig {
|
|||
}
|
||||
|
||||
fn build(self) -> impl Future<Item = (), Error = Error> {
|
||||
lazy(|| {
|
||||
let puller = Pull::builder(self.config.context.clone())
|
||||
Pull::builder(self.config.context.clone())
|
||||
.bind(&self.address)
|
||||
.build()?;
|
||||
|
||||
.build()
|
||||
.map(|puller| {
|
||||
let config = PullConfig {
|
||||
puller,
|
||||
address: self.address,
|
||||
|
@ -125,8 +125,7 @@ impl ResetPullConfig {
|
|||
};
|
||||
|
||||
tokio::spawn(config.run());
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.from_err()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use failure::Error;
|
||||
use futures::{
|
||||
future::{lazy, poll_fn},
|
||||
stream::iter_ok,
|
||||
Future, Stream,
|
||||
};
|
||||
use futures::{future::poll_fn, stream::iter_ok, Future, Stream};
|
||||
#[cfg(feature = "futures-zmq")]
|
||||
use futures_zmq::{prelude::*, Multipart, Push};
|
||||
use jobs_core::{JobInfo, Storage};
|
||||
use log::{error, info};
|
||||
use tokio::timer::{Delay, Interval};
|
||||
use tokio_threadpool::blocking;
|
||||
#[cfg(feature = "tokio-zmq")]
|
||||
use tokio_zmq::{prelude::*, Multipart, Push};
|
||||
use zmq::Message;
|
||||
|
||||
|
@ -136,12 +136,11 @@ impl ResetPushConfig {
|
|||
}
|
||||
|
||||
fn build(self) -> impl Future<Item = (), Error = Error> {
|
||||
lazy(|| {
|
||||
info!("Building and spawning new server");
|
||||
let pusher = Push::builder(self.config.context.clone())
|
||||
Push::builder(self.config.context.clone())
|
||||
.bind(&self.address)
|
||||
.build()?;
|
||||
|
||||
.build()
|
||||
.map(|pusher| {
|
||||
let config = PushConfig {
|
||||
pusher,
|
||||
address: self.address,
|
||||
|
@ -151,8 +150,7 @@ impl ResetPushConfig {
|
|||
};
|
||||
|
||||
tokio::spawn(config.run());
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.from_err()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ use std::{sync::Arc, time::Duration};
|
|||
use failure::Error;
|
||||
use futures::{future::poll_fn, Future, Stream};
|
||||
use jobs_core::Storage;
|
||||
use log::{error, info};
|
||||
use tokio::timer::{Delay, Interval};
|
||||
use tokio_threadpool::blocking;
|
||||
|
||||
|
|
|
@ -2,7 +2,11 @@ use std::sync::Arc;
|
|||
|
||||
use failure::Error;
|
||||
use futures::{future::IntoFuture, Future};
|
||||
#[cfg(feature = "futures-zmq")]
|
||||
use futures_zmq::{prelude::*, Push};
|
||||
use jobs_core::JobInfo;
|
||||
use log::{debug, trace};
|
||||
#[cfg(feature = "tokio-zmq")]
|
||||
use tokio_zmq::{prelude::*, Push};
|
||||
use zmq::{Context, Message};
|
||||
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use failure::Error;
|
||||
use failure::{Error, Fail};
|
||||
use futures::{
|
||||
future::{lazy, Either, IntoFuture},
|
||||
future::{Either, IntoFuture},
|
||||
Future, Stream,
|
||||
};
|
||||
#[cfg(feature = "futures-zmq")]
|
||||
use futures_zmq::{prelude::*, Multipart, Pull, Push};
|
||||
use jobs_core::{JobInfo, Processors};
|
||||
use log::{error, info};
|
||||
use tokio::timer::Delay;
|
||||
#[cfg(feature = "tokio-zmq")]
|
||||
use tokio_zmq::{prelude::*, Multipart, Pull, Push};
|
||||
use zmq::{Context, Message};
|
||||
|
||||
|
@ -98,15 +102,15 @@ impl ResetWorker {
|
|||
}
|
||||
|
||||
fn build(self) -> impl Future<Item = (), Error = Error> {
|
||||
lazy(|| {
|
||||
let push = Push::builder(self.context.clone())
|
||||
Push::builder(self.context.clone())
|
||||
.connect(&self.push_address)
|
||||
.build()?;
|
||||
|
||||
let pull = Pull::builder(self.context.clone())
|
||||
.build()
|
||||
.join(
|
||||
Pull::builder(self.context.clone())
|
||||
.connect(&self.pull_address)
|
||||
.build()?;
|
||||
|
||||
.build(),
|
||||
)
|
||||
.map(|(push, pull)| {
|
||||
let config = Worker {
|
||||
push,
|
||||
pull,
|
||||
|
@ -118,9 +122,8 @@ impl ResetWorker {
|
|||
};
|
||||
|
||||
tokio::spawn(config.run());
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.from_err()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
use failure::Fail;
|
||||
use futures::Future;
|
||||
use jobs_core::{Processor, Processors};
|
||||
use log::{error, info};
|
||||
use zmq::Context;
|
||||
|
||||
mod config;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
use failure::Error;
|
||||
use futures::{future::lazy, Future};
|
||||
use failure::{Error, Fail};
|
||||
use futures::Future;
|
||||
#[cfg(feature = "futures-zmq")]
|
||||
use futures_zmq::{prelude::*, Req};
|
||||
#[cfg(feature = "tokio-zmq")]
|
||||
use tokio_zmq::{prelude::*, Req};
|
||||
use zmq::{Context, Message};
|
||||
|
||||
|
@ -12,11 +15,10 @@ impl PortMap {
|
|||
address: String,
|
||||
context: Arc<Context>,
|
||||
) -> impl Future<Item = BTreeMap<String, usize>, Error = Error> {
|
||||
lazy(move || {
|
||||
let req = Req::builder(context.clone()).connect(&address).build()?;
|
||||
|
||||
Ok(req)
|
||||
})
|
||||
Req::builder(context.clone())
|
||||
.connect(&address)
|
||||
.build()
|
||||
.from_err()
|
||||
.and_then(|req| {
|
||||
Message::from_slice(b"h")
|
||||
.map_err(Error::from)
|
||||
|
|
Loading…
Reference in a new issue