Backend

Trait Backend 

Source
pub trait Backend<Args> {
    type IdType: Clone;
    type Context: Default;
    type Error;
    type Codec;
    type Stream: Stream<Item = Result<Option<Task<Args, Self::Context, Self::IdType>>, Self::Error>>;
    type Beat: Stream<Item = Result<(), Self::Error>>;
    type Layer;

    // Required methods
    fn heartbeat(&self, worker: &WorkerContext) -> Self::Beat;
    fn middleware(&self) -> Self::Layer;
    fn poll(self, worker: &WorkerContext) -> Self::Stream;
}
Expand description

The Backend trait defines how workers get and manage tasks from a backend.

In other languages, this might be called a “Queue”, “Broker”, etc.

Required Associated Types§

Source

type IdType: Clone

The type used to uniquely identify tasks.

Source

type Context: Default

Context associated with each task.

Source

type Error

The error type returned by backend operations

Source

type Codec

The codec used for serialization/deserialization of tasks.

Source

type Stream: Stream<Item = Result<Option<Task<Args, Self::Context, Self::IdType>>, Self::Error>>

A stream of tasks provided by the backend.

Source

type Beat: Stream<Item = Result<(), Self::Error>>

A stream representing heartbeat signals.

Source

type Layer

The type representing backend middleware layer.

Required Methods§

Source

fn heartbeat(&self, worker: &WorkerContext) -> Self::Beat

Returns a heartbeat stream for the given worker.

Source

fn middleware(&self) -> Self::Layer

Returns the backend’s middleware layer.

Source

fn poll(self, worker: &WorkerContext) -> Self::Stream

Polls the backend for tasks for the given worker.

Implementors§

Source§

impl<Args, Ctx, S, TSink, Err> Backend<Args> for Pipe<S, TSink, Args, Ctx>
where S: Stream<Item = Result<Args, Err>> + Send + 'static, TSink: Backend<Args, Context = Ctx> + Sink<Task<Args, Ctx, TSink::IdType>> + Clone + Unpin + Send + 'static, <TSink as Backend<Args>>::Error: Into<BoxDynError> + Send + Sync + 'static, TSink::Beat: Send + 'static, TSink::IdType: Send + Clone + 'static, TSink::Stream: Send + 'static, Args: Send + 'static, Ctx: Send + 'static + Default, Err: Into<BoxDynError> + Send + Sync + 'static, <TSink as Sink<Task<Args, Ctx, TSink::IdType>>>::Error: Into<BoxDynError> + Send + Sync + 'static,

Source§

type IdType = <TSink as Backend<Args>>::IdType

Source§

type Context = Ctx

Source§

type Stream = Pin<Box<dyn Stream<Item = Result<Option<Task<Args, Ctx, <Pipe<S, TSink, Args, Ctx> as Backend<Args>>::IdType>>, PipeError>> + Send>>

Source§

type Layer = <TSink as Backend<Args>>::Layer

Source§

type Beat = Pin<Box<dyn Stream<Item = Result<(), PipeError>> + Send>>

Source§

type Error = PipeError

Source§

type Codec = <TSink as Backend<Args>>::Codec

Source§

impl<Args, DB, Fetch, Sink, IdType: Clone, E, Ctx: Default, Encode, Config> Backend<Args> for CustomBackend<Args, DB, Fetch, Sink, IdType, Encode, Config>
where Fetch: Stream<Item = Result<Option<Task<Encode::Compact, Ctx, IdType>>, E>> + Send + 'static, Encode: Codec<Args> + Send + 'static, Encode::Error: Into<BoxDynError>, E: Into<BoxDynError>,

Source§

type IdType = IdType

Source§

type Context = Ctx

Source§

type Error = Box<dyn Error + Sync + Send>

Source§

type Stream = Pin<Box<dyn Stream<Item = Result<Option<Task<Args, Ctx, IdType>>, Box<dyn Error + Sync + Send>>> + Send>>

Source§

type Codec = Encode

Source§

type Beat = Pin<Box<dyn Stream<Item = Result<(), <CustomBackend<Args, DB, Fetch, Sink, IdType, Encode, Config> as Backend<Args>>::Error>> + Send>>

Source§

type Layer = Identity

Source§

impl<Args: 'static + Clone + Send, Ctx: 'static + Default> Backend<Args> for MemoryStorage<Args, Ctx>

Source§

impl<Args: 'static + Send + DeserializeOwned + Unpin> Backend<Args> for JsonStorage<Args>