Backend

Trait Backend 

Source
pub trait Backend {
    type Args;
    type IdType: Clone;
    type Context: Default;
    type Error;
    type Codec: Codec<Self::Args, Compact = Self::Compact>;
    type Compact;
    type Stream: Stream<Item = Result<Option<Task<Self::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 Args

The type of arguments the backend handles.

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: Codec<Self::Args, Compact = Self::Compact>

The codec used for serialization/deserialization of tasks.

Source

type Compact

The compact representation of task arguments.

Source

type Stream: Stream<Item = Result<Option<Task<Self::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> Backend for JsonStorage<Args>
where Args: 'static + Send + Serialize + DeserializeOwned + Unpin,

Available on crate feature json only.
Source§

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

Source§

type Args = Args

Source§

type IdType = <TSink as Backend>::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>::IdType>>, PipeError>> + Send>>

Source§

type Layer = <TSink as Backend>::Layer

Source§

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

Source§

type Error = PipeError

Source§

type Codec = <TSink as Backend>::Codec

Source§

type Compact = <TSink as Backend>::Compact

Source§

impl<Args, DB, Fetch, Sink, IdType: Clone, E, Ctx: Default, Encode, Config> Backend 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 Args = Args

Source§

type IdType = IdType

Source§

type Context = Ctx

Source§

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

Source§

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

Source§

type Codec = Encode

Source§

type Compact = <Encode as Codec<Args>>::Compact

Source§

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

Source§

type Layer = Identity

Source§

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