Struct tourniquet::RoundRobin [−][src]
pub struct RoundRobin<SvcSrc, Svc, E, Conn> where
Conn: Connector<SvcSrc, Svc, E>, { /* fields omitted */ }
Expand description
Round Robin manager.
This holds a list of services, a way to connect to said services, and a way to run stuff against this connected service.
Implementations
impl<SvcSrc, B, Conn> RoundRobin<SvcSrc, Celery<B>, CeleryError, Conn> where
SvcSrc: Debug,
B: Broker + 'static,
Conn: Connector<SvcSrc, Celery<B>, CeleryError>,
impl<SvcSrc, B, Conn> RoundRobin<SvcSrc, Celery<B>, CeleryError, Conn> where
SvcSrc: Debug,
B: Broker + 'static,
Conn: Connector<SvcSrc, Celery<B>, CeleryError>,
pub async fn send_task<T, F>(
&self,
task_gen: F
) -> Result<AsyncResult, CeleryError> where
T: Task + 'static,
F: Fn() -> Signature<T>,
pub async fn send_task<T, F>(
&self,
task_gen: F
) -> Result<AsyncResult, CeleryError> where
T: Task + 'static,
F: Fn() -> Signature<T>,
Send a Celery task.
The task_gen
argument returns a signature for each attempt, should each attempt hold a
different value (e.g. trace id, attempt id, timestamp, …).
Example
#[celery::task]
async fn do_work(work: String) -> TaskResult<()> {
// Some work
Ok(())
}
let rr = RoundRobin::new(
vec!["amqp://rabbit01:5672/".to_owned(), "amqp://rabbit02:5672".to_owned()],
CeleryConnector { name: "rr", routes: &[("*", "my_route")], ..Default::default() },
);
rr.send_task(|| do_work::new(work.clone())).await.expect("Failed to send task");
Build a new round-robin manager.
The connector is a struct that yields a connected handler to the service, from its service “source” (usually an URL). Note that the connector is lazily executed on demand when a connection is needed.
Example
use std::{io::Error, net::IpAddr};
use tokio::net::TcpStream;
use tourniquet::{Connector, RoundRobin};
struct Conn(u16);
#[async_trait]
impl Connector<IpAddr, Mutex<TcpStream>, Error> for Conn {
async fn connect(&self, src: &IpAddr) -> Result<Mutex<TcpStream>, Error> {
let Conn(ref port) = self;
TcpStream::connect((*src, *port)).await.map(Mutex::new)
}
}
let rr = RoundRobin::new(
vec!["185.30.166.38".parse().unwrap(), "66.110.9.37".parse().unwrap()],
Conn(6667),
);
Set how many times we will try the next service in case of failure.
Auto Trait Implementations
impl<SvcSrc, Svc, E, Conn> !RefUnwindSafe for RoundRobin<SvcSrc, Svc, E, Conn>
impl<SvcSrc, Svc, E, Conn> Send for RoundRobin<SvcSrc, Svc, E, Conn> where
Conn: Send,
E: Send,
Svc: Send + Sync,
SvcSrc: Send,
impl<SvcSrc, Svc, E, Conn> Sync for RoundRobin<SvcSrc, Svc, E, Conn> where
Conn: Sync,
E: Sync,
Svc: Send + Sync,
SvcSrc: Sync,
impl<SvcSrc, Svc, E, Conn> Unpin for RoundRobin<SvcSrc, Svc, E, Conn> where
Conn: Unpin,
E: Unpin,
SvcSrc: Unpin,
impl<SvcSrc, Svc, E, Conn> !UnwindSafe for RoundRobin<SvcSrc, Svc, E, Conn>
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more