mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-24 21:11:03 +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]
|
[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]
|
[dependencies.jobs-actix]
|
||||||
version = "0.1"
|
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"
|
serde_json = "1.0"
|
||||||
tokio = "0.1"
|
tokio = "0.1"
|
||||||
tokio-threadpool = "0.1"
|
tokio-threadpool = "0.1"
|
||||||
tokio-zmq = "0.6.1"
|
|
||||||
zmq = "0.8"
|
zmq = "0.8"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["tokio-zmq"]
|
||||||
|
|
||||||
[dependencies.jobs-core]
|
[dependencies.jobs-core]
|
||||||
version = "0.1"
|
version = "0.1"
|
||||||
path = "../jobs-core"
|
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;
|
use failure::Error;
|
||||||
|
|
||||||
mod server;
|
mod server;
|
||||||
|
|
|
@ -4,9 +4,10 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use failure::Error;
|
use failure::{Error, Fail};
|
||||||
use futures::{future::poll_fn, Future};
|
use futures::{future::poll_fn, Future};
|
||||||
use jobs_core::Storage;
|
use jobs_core::Storage;
|
||||||
|
use log::{error, info};
|
||||||
use tokio_threadpool::blocking;
|
use tokio_threadpool::blocking;
|
||||||
use zmq::Context;
|
use zmq::Context;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
use std::{collections::BTreeMap, sync::Arc, time::Duration};
|
use std::{collections::BTreeMap, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use failure::Error;
|
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;
|
use tokio::timer::Delay;
|
||||||
|
#[cfg(feature = "tokio-zmq")]
|
||||||
use tokio_zmq::{prelude::*, Multipart, Rep};
|
use tokio_zmq::{prelude::*, Multipart, Rep};
|
||||||
use zmq::Message;
|
use zmq::Message;
|
||||||
|
|
||||||
|
@ -85,21 +89,19 @@ impl ResetPortMapConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(self) -> impl Future<Item = (), Error = Error> {
|
fn build(self) -> impl Future<Item = (), Error = Error> {
|
||||||
lazy(|| {
|
Rep::builder(self.config.context.clone())
|
||||||
let rep = Rep::builder(self.config.context.clone())
|
.bind(&self.address)
|
||||||
.bind(&self.address)
|
.build()
|
||||||
.build()?;
|
.map(|rep| {
|
||||||
|
let config = PortMapConfig {
|
||||||
|
rep,
|
||||||
|
address: self.address,
|
||||||
|
port_map: self.port_map,
|
||||||
|
config: self.config,
|
||||||
|
};
|
||||||
|
|
||||||
let config = PortMapConfig {
|
tokio::spawn(config.run());
|
||||||
rep,
|
})
|
||||||
address: self.address,
|
.from_err()
|
||||||
port_map: self.port_map,
|
|
||||||
config: self.config,
|
|
||||||
};
|
|
||||||
|
|
||||||
tokio::spawn(config.run());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
use failure::Error;
|
use failure::{Error, Fail};
|
||||||
use futures::{
|
use futures::{future::poll_fn, Future, Stream};
|
||||||
future::{lazy, poll_fn},
|
#[cfg(feature = "futures-zmq")]
|
||||||
Future, Stream,
|
use futures_zmq::{prelude::*, Multipart, Pull};
|
||||||
};
|
|
||||||
use jobs_core::{JobInfo, Storage};
|
use jobs_core::{JobInfo, Storage};
|
||||||
|
use log::{error, info, trace};
|
||||||
use tokio::timer::Delay;
|
use tokio::timer::Delay;
|
||||||
use tokio_threadpool::blocking;
|
use tokio_threadpool::blocking;
|
||||||
|
#[cfg(feature = "tokio-zmq")]
|
||||||
use tokio_zmq::{prelude::*, Multipart, Pull};
|
use tokio_zmq::{prelude::*, Multipart, Pull};
|
||||||
|
|
||||||
use crate::server::{coerce, Config};
|
use crate::server::{coerce, Config};
|
||||||
|
@ -112,21 +113,19 @@ impl ResetPullConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(self) -> impl Future<Item = (), Error = Error> {
|
fn build(self) -> impl Future<Item = (), Error = Error> {
|
||||||
lazy(|| {
|
Pull::builder(self.config.context.clone())
|
||||||
let puller = Pull::builder(self.config.context.clone())
|
.bind(&self.address)
|
||||||
.bind(&self.address)
|
.build()
|
||||||
.build()?;
|
.map(|puller| {
|
||||||
|
let config = PullConfig {
|
||||||
|
puller,
|
||||||
|
address: self.address,
|
||||||
|
storage: self.storage,
|
||||||
|
config: self.config,
|
||||||
|
};
|
||||||
|
|
||||||
let config = PullConfig {
|
tokio::spawn(config.run());
|
||||||
puller,
|
})
|
||||||
address: self.address,
|
.from_err()
|
||||||
storage: self.storage,
|
|
||||||
config: self.config,
|
|
||||||
};
|
|
||||||
|
|
||||||
tokio::spawn(config.run());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use futures::{
|
use futures::{future::poll_fn, stream::iter_ok, Future, Stream};
|
||||||
future::{lazy, poll_fn},
|
#[cfg(feature = "futures-zmq")]
|
||||||
stream::iter_ok,
|
use futures_zmq::{prelude::*, Multipart, Push};
|
||||||
Future, Stream,
|
|
||||||
};
|
|
||||||
use jobs_core::{JobInfo, Storage};
|
use jobs_core::{JobInfo, Storage};
|
||||||
|
use log::{error, info};
|
||||||
use tokio::timer::{Delay, Interval};
|
use tokio::timer::{Delay, Interval};
|
||||||
use tokio_threadpool::blocking;
|
use tokio_threadpool::blocking;
|
||||||
|
#[cfg(feature = "tokio-zmq")]
|
||||||
use tokio_zmq::{prelude::*, Multipart, Push};
|
use tokio_zmq::{prelude::*, Multipart, Push};
|
||||||
use zmq::Message;
|
use zmq::Message;
|
||||||
|
|
||||||
|
@ -136,23 +136,21 @@ impl ResetPushConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(self) -> impl Future<Item = (), Error = Error> {
|
fn build(self) -> impl Future<Item = (), Error = Error> {
|
||||||
lazy(|| {
|
info!("Building and spawning new server");
|
||||||
info!("Building and spawning new server");
|
Push::builder(self.config.context.clone())
|
||||||
let pusher = Push::builder(self.config.context.clone())
|
.bind(&self.address)
|
||||||
.bind(&self.address)
|
.build()
|
||||||
.build()?;
|
.map(|pusher| {
|
||||||
|
let config = PushConfig {
|
||||||
|
pusher,
|
||||||
|
address: self.address,
|
||||||
|
queue: self.queue,
|
||||||
|
storage: self.storage,
|
||||||
|
config: self.config,
|
||||||
|
};
|
||||||
|
|
||||||
let config = PushConfig {
|
tokio::spawn(config.run());
|
||||||
pusher,
|
})
|
||||||
address: self.address,
|
.from_err()
|
||||||
queue: self.queue,
|
|
||||||
storage: self.storage,
|
|
||||||
config: self.config,
|
|
||||||
};
|
|
||||||
|
|
||||||
tokio::spawn(config.run());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use std::{sync::Arc, time::Duration};
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use futures::{future::poll_fn, Future, Stream};
|
use futures::{future::poll_fn, Future, Stream};
|
||||||
use jobs_core::Storage;
|
use jobs_core::Storage;
|
||||||
|
use log::{error, info};
|
||||||
use tokio::timer::{Delay, Interval};
|
use tokio::timer::{Delay, Interval};
|
||||||
use tokio_threadpool::blocking;
|
use tokio_threadpool::blocking;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,11 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use futures::{future::IntoFuture, Future};
|
use futures::{future::IntoFuture, Future};
|
||||||
|
#[cfg(feature = "futures-zmq")]
|
||||||
|
use futures_zmq::{prelude::*, Push};
|
||||||
use jobs_core::JobInfo;
|
use jobs_core::JobInfo;
|
||||||
|
use log::{debug, trace};
|
||||||
|
#[cfg(feature = "tokio-zmq")]
|
||||||
use tokio_zmq::{prelude::*, Push};
|
use tokio_zmq::{prelude::*, Push};
|
||||||
use zmq::{Context, Message};
|
use zmq::{Context, Message};
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
use failure::Error;
|
use failure::{Error, Fail};
|
||||||
use futures::{
|
use futures::{
|
||||||
future::{lazy, Either, IntoFuture},
|
future::{Either, IntoFuture},
|
||||||
Future, Stream,
|
Future, Stream,
|
||||||
};
|
};
|
||||||
|
#[cfg(feature = "futures-zmq")]
|
||||||
|
use futures_zmq::{prelude::*, Multipart, Pull, Push};
|
||||||
use jobs_core::{JobInfo, Processors};
|
use jobs_core::{JobInfo, Processors};
|
||||||
|
use log::{error, info};
|
||||||
use tokio::timer::Delay;
|
use tokio::timer::Delay;
|
||||||
|
#[cfg(feature = "tokio-zmq")]
|
||||||
use tokio_zmq::{prelude::*, Multipart, Pull, Push};
|
use tokio_zmq::{prelude::*, Multipart, Pull, Push};
|
||||||
use zmq::{Context, Message};
|
use zmq::{Context, Message};
|
||||||
|
|
||||||
|
@ -98,29 +102,28 @@ impl ResetWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(self) -> impl Future<Item = (), Error = Error> {
|
fn build(self) -> impl Future<Item = (), Error = Error> {
|
||||||
lazy(|| {
|
Push::builder(self.context.clone())
|
||||||
let push = Push::builder(self.context.clone())
|
.connect(&self.push_address)
|
||||||
.connect(&self.push_address)
|
.build()
|
||||||
.build()?;
|
.join(
|
||||||
|
Pull::builder(self.context.clone())
|
||||||
|
.connect(&self.pull_address)
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
.map(|(push, pull)| {
|
||||||
|
let config = Worker {
|
||||||
|
push,
|
||||||
|
pull,
|
||||||
|
push_address: self.push_address,
|
||||||
|
pull_address: self.pull_address,
|
||||||
|
queue: self.queue,
|
||||||
|
processors: self.processors,
|
||||||
|
context: self.context,
|
||||||
|
};
|
||||||
|
|
||||||
let pull = Pull::builder(self.context.clone())
|
tokio::spawn(config.run());
|
||||||
.connect(&self.pull_address)
|
})
|
||||||
.build()?;
|
.from_err()
|
||||||
|
|
||||||
let config = Worker {
|
|
||||||
push,
|
|
||||||
pull,
|
|
||||||
push_address: self.push_address,
|
|
||||||
pull_address: self.pull_address,
|
|
||||||
queue: self.queue,
|
|
||||||
processors: self.processors,
|
|
||||||
context: self.context,
|
|
||||||
};
|
|
||||||
|
|
||||||
tokio::spawn(config.run());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use std::{collections::BTreeMap, sync::Arc};
|
use std::{collections::BTreeMap, sync::Arc};
|
||||||
|
|
||||||
|
use failure::Fail;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use jobs_core::{Processor, Processors};
|
use jobs_core::{Processor, Processors};
|
||||||
|
use log::{error, info};
|
||||||
use zmq::Context;
|
use zmq::Context;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
use std::{collections::BTreeMap, sync::Arc};
|
use std::{collections::BTreeMap, sync::Arc};
|
||||||
|
|
||||||
use failure::Error;
|
use failure::{Error, Fail};
|
||||||
use futures::{future::lazy, Future};
|
use futures::Future;
|
||||||
|
#[cfg(feature = "futures-zmq")]
|
||||||
|
use futures_zmq::{prelude::*, Req};
|
||||||
|
#[cfg(feature = "tokio-zmq")]
|
||||||
use tokio_zmq::{prelude::*, Req};
|
use tokio_zmq::{prelude::*, Req};
|
||||||
use zmq::{Context, Message};
|
use zmq::{Context, Message};
|
||||||
|
|
||||||
|
@ -12,24 +15,23 @@ impl PortMap {
|
||||||
address: String,
|
address: String,
|
||||||
context: Arc<Context>,
|
context: Arc<Context>,
|
||||||
) -> impl Future<Item = BTreeMap<String, usize>, Error = Error> {
|
) -> impl Future<Item = BTreeMap<String, usize>, Error = Error> {
|
||||||
lazy(move || {
|
Req::builder(context.clone())
|
||||||
let req = Req::builder(context.clone()).connect(&address).build()?;
|
.connect(&address)
|
||||||
|
.build()
|
||||||
|
.from_err()
|
||||||
|
.and_then(|req| {
|
||||||
|
Message::from_slice(b"h")
|
||||||
|
.map_err(Error::from)
|
||||||
|
.map(move |msg| (req, msg.into()))
|
||||||
|
})
|
||||||
|
.and_then(|(req, msg)| req.send(msg).and_then(|req| req.recv()).from_err())
|
||||||
|
.and_then(|(mut multipart, _)| {
|
||||||
|
let msg = multipart.pop_front().ok_or(EmptyMessage)?;
|
||||||
|
|
||||||
Ok(req)
|
let map = serde_json::from_slice(&msg)?;
|
||||||
})
|
|
||||||
.and_then(|req| {
|
|
||||||
Message::from_slice(b"h")
|
|
||||||
.map_err(Error::from)
|
|
||||||
.map(move |msg| (req, msg.into()))
|
|
||||||
})
|
|
||||||
.and_then(|(req, msg)| req.send(msg).and_then(|req| req.recv()).from_err())
|
|
||||||
.and_then(|(mut multipart, _)| {
|
|
||||||
let msg = multipart.pop_front().ok_or(EmptyMessage)?;
|
|
||||||
|
|
||||||
let map = serde_json::from_slice(&msg)?;
|
Ok(map)
|
||||||
|
})
|
||||||
Ok(map)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue