RedisStorage

Struct RedisStorage 

Source
pub struct RedisStorage<Args, Conn = ConnectionManager, C = JsonCodec<Vec<u8>>> { /* private fields */ }
Expand description

Represents a Backend that uses Redis for storage.

§Feature Support

§Features

FeatureStatusDescription
TaskSinkAbility to push new tasks
MakeSharedShare the same connection across multiple workers
WorkflowSupports workflows and orchestration
Web InterfaceSupports apalis-board for monitoring and managing tasks
WaitForCompletionWait for tasks to complete without blocking
SerializationSupports multiple serialization formats such as JSON and MessagePack
RegisterWorkerAllow registering a worker with the backend
ResumeAbandonedResume abandoned tasks

Key: ✅ : Supported | ⚠️ : Not implemented | ❌ : Not Supported | ❗ Limited support

Tests:
§TaskSink
#[tokio::main]
async fn main() {
    // let mut backend = /* snip */;
    
    backend.push(42).await.unwrap();

    async fn task(task: u32, worker: WorkerContext) {
        worker.stop().unwrap();
    }
    let worker = WorkerBuilder::new("task-sink-test")
        .backend(backend)
        .build(task);
    worker.run().await.unwrap();
}
§Workflow
#[tokio::main]
async fn main() {
    // let mut backend = /* snip */;
    
    backend.push_start(42).await.unwrap();

    async fn task1(task: u32, worker: WorkerContext) -> u32 {
        task + 99 
    }
    async fn task2(task: u32, worker: WorkerContext) -> u32 {
        task + 1 
    }
    async fn task3(task: u32, worker: WorkerContext) {
        assert_eq!(task, 142);
        worker.stop().unwrap();
    }
    let workflow = Workflow::new("test-workflow")
       .and_then(task1)
       .and_then(task2)
       .and_then(task3);
    let worker = WorkerBuilder::new("workflow-test")
        .backend(backend)
        .build(workflow);
    worker.run().await.unwrap();
}
§WebUI
#[tokio::main]
async fn main() {
    // let mut backend = /* snip */;
    
    fn assert_web_ui<B: Expose<u32>>(backend: B) {};
    assert_web_ui(backend);
}
§WaitForCompletion
#[tokio::main]
async fn main() {
    // let mut backend = /* snip */;
    
    fn assert_wait_for_completion<B: WaitForCompletion<(), Args = u32>>(backend: B) {};
    assert_wait_for_completion(backend);
}

Implementations§

Source§

impl<Args, Conn, C> RedisStorage<Args, Conn, C>
where Args: Unpin + Send + Sync + 'static, Conn: ConnectionLike + Send + Sync + 'static, C: Codec<Args, Compact = Vec<u8>>, C::Error: Into<BoxDynError>,

Source

pub async fn fetch_next( worker: &WorkerContext, config: &RedisConfig, conn: &mut Conn, ) -> Result<Vec<Task<Vec<u8>, RedisContext, Ulid>>, RedisError>

Fetches the next batch of tasks for the given worker.

Source§

impl<T, Conn: Clone> RedisStorage<T, Conn, JsonCodec<Vec<u8>>>

Source

pub fn new(conn: Conn) -> RedisStorage<T, Conn, JsonCodec<Vec<u8>>>

Start a new connection

Source

pub fn new_with_config( conn: Conn, config: RedisConfig, ) -> RedisStorage<T, Conn, JsonCodec<Vec<u8>>>

Start a connection with a custom config

Source

pub fn new_with_codec<K>( conn: Conn, config: RedisConfig, ) -> RedisStorage<T, Conn, K>
where K: Sync + Send + 'static,

Start a new connection providing custom config and a codec

Source

pub fn get_connection(&self) -> &Conn

Get current connection

Source

pub fn get_config(&self) -> &RedisConfig

Get the config used by the storage

Trait Implementations§

Source§

impl<Args, Conn, C> Backend for RedisStorage<Args, Conn, C>
where Args: Unpin + Send + Sync + 'static, Conn: Clone + ConnectionLike + Send + Sync + 'static, C: Codec<Args, Compact = Vec<u8>> + Unpin + Send + 'static, C::Error: Into<BoxDynError>,

Source§

type Args = Args

The type of arguments the backend handles.
Source§

type Stream = Pin<Box<dyn Stream<Item = Result<Option<Task<Args, RedisContext, Ulid>>, RedisError>> + Send>>

A stream of tasks provided by the backend.
Source§

type IdType = Ulid

The type used to uniquely identify tasks.
Source§

type Error = RedisError

The error type returned by backend operations
Source§

type Layer = AcknowledgeLayer<RedisAck<Conn, C>>

The type representing backend middleware layer.
Source§

type Context = RedisContext

Context associated with each task.
Source§

type Beat = Pin<Box<dyn Stream<Item = Result<(), <RedisStorage<Args, Conn, C> as Backend>::Error>> + Send>>

A stream representing heartbeat signals.
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.
Source§

impl<Args, Conn, C> BackendExt for RedisStorage<Args, Conn, C>
where Args: Unpin + Send + Sync + 'static, Conn: Clone + ConnectionLike + Send + Sync + 'static, C: Codec<Args, Compact = Vec<u8>> + Unpin + Send + 'static, C::Error: Into<BoxDynError>,

Source§

type Compact = Vec<u8>

The compact representation of task arguments.
Source§

type Codec = C

The codec used for serialization/deserialization of tasks.
Source§

type CompactStream = Pin<Box<dyn Stream<Item = Result<Option<Task<<RedisStorage<Args, Conn, C> as BackendExt>::Compact, RedisContext, Ulid>>, RedisError>> + Send>>

A stream of encoded tasks provided by the backend.
Source§

fn poll_compact(self, worker: &WorkerContext) -> Self::CompactStream

Polls the backend for encoded tasks for the given worker.
Source§

impl<Args, Conn: Clone, Cdc: Clone> Clone for RedisStorage<Args, Conn, Cdc>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Args: Sync, Conn, C> ConfigExt for RedisStorage<Args, Conn, C>
where RedisStorage<Args, Conn, C>: BackendExt<Context = RedisContext, Compact = Vec<u8>, IdType = Ulid, Error = RedisError>,

Source§

fn get_queue(&self) -> Queue

Get the queue configuration
Source§

impl<Args: Debug, Conn: Debug, C: Debug> Debug for RedisStorage<Args, Conn, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Args, Conn, C> FetchById<Args> for RedisStorage<Args, Conn, C>
where RedisStorage<Args, Conn, C>: BackendExt<Context = RedisContext, Compact = Vec<u8>, IdType = Ulid, Error = RedisError>, C: Codec<Args, Compact = Vec<u8>> + Send, C::Error: Error + Send + Sync + 'static, Args: 'static + Send, Conn: ConnectionLike + Send,

Source§

async fn fetch_by_id( &mut self, task_id: &TaskId<Self::IdType>, ) -> Result<Option<RedisTask<Args>>, Self::Error>

Fetch a task by its unique identifier
Source§

impl<Args, Conn, C> ListAllTasks for RedisStorage<Args, Conn, C>
where RedisStorage<Args, Conn, C>: BackendExt<Context = RedisContext, Compact = Vec<u8>, IdType = Ulid, Error = RedisError>, C: Codec<Args, Compact = Vec<u8>> + Send + Sync, C::Error: Error + Send + Sync + 'static, Args: 'static + Send + Sync, Conn: ConnectionLike + Send + Sync + Clone,

Source§

async fn list_all_tasks( &self, filter: &Filter, ) -> Result<Vec<RedisTask<Vec<u8>>>, Self::Error>

List tasks matching the given filter in all queues
Source§

impl<Args, Conn, C> ListQueues for RedisStorage<Args, Conn, C>
where RedisStorage<Args, Conn, C>: BackendExt<Context = RedisContext, Compact = Vec<u8>, IdType = Ulid, Error = RedisError>, C: Codec<Args, Compact = Vec<u8>> + Send, C::Error: Error + Send + Sync + 'static, Args: 'static + Send, Conn: ConnectionLike + Send + Clone,

Source§

fn list_queues( &self, ) -> impl Future<Output = Result<Vec<QueueInfo>, Self::Error>> + Send

List all available queues in the backend
Source§

impl<Args, Conn, C> ListTasks<Args> for RedisStorage<Args, Conn, C>
where RedisStorage<Args, Conn, C>: BackendExt<Context = RedisContext, Compact = Vec<u8>, IdType = Ulid, Error = RedisError>, C: Codec<Args, Compact = Vec<u8>> + Send + Sync, C::Error: Error + Send + Sync + 'static, Args: 'static + Send + Sync, Conn: ConnectionLike + Send + Clone + Sync,

Source§

async fn list_tasks( &self, queue: &str, filter: &Filter, ) -> Result<Vec<RedisTask<Args>>, Self::Error>

List tasks matching the given filter in the current queue
Source§

impl<Args, Conn, C> ListWorkers for RedisStorage<Args, Conn, C>
where RedisStorage<Args, Conn, C>: BackendExt<Context = RedisContext, Compact = Vec<u8>, IdType = Ulid, Error = RedisError>, C: Codec<Args, Compact = Vec<u8>> + Send, C::Error: Error + Send + Sync + 'static, Args: 'static + Send + Sync, Conn: ConnectionLike + Send + Clone,

Source§

fn list_workers( &self, queue: &str, ) -> impl Future<Output = Result<Vec<RunningWorker>, Self::Error>> + Send

List all registered workers in the current queue
Source§

fn list_all_workers( &self, ) -> impl Future<Output = Result<Vec<RunningWorker>, Self::Error>> + Send

List all registered workers in all queues
Source§

impl<Args, Conn, C> Metrics for RedisStorage<Args, Conn, C>
where RedisStorage<Args, Conn, C>: BackendExt<Context = RedisContext, Compact = Vec<u8>, IdType = Ulid, Error = RedisError>, C: Codec<Args, Compact = Vec<u8>> + Send + Sync, C::Error: Error + Send + Sync + 'static, Args: 'static + Send + Sync, Conn: ConnectionLike + Send + Clone + Sync,

Source§

fn global( &self, ) -> impl Future<Output = Result<Vec<Statistic>, Self::Error>> + Send

Collects and returns global statistics from the backend
Source§

fn fetch_by_queue( &self, queue_id: &str, ) -> impl Future<Output = Result<Vec<Statistic>, Self::Error>> + Send

Collects and returns statistics for a specific queue
Source§

impl<Args, Cdc, Conn> Sink<Task<Vec<u8>, RedisContext, Ulid>> for RedisStorage<Args, Conn, Cdc>
where Args: Unpin, Conn: ConnectionLike + Unpin + Send + Clone + 'static, Cdc: Unpin,

Source§

type Error = RedisError

The type of value produced by the sink when an error occurs.
Source§

fn poll_ready( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
Source§

fn start_send( self: Pin<&mut Self>, item: Task<Vec<u8>, RedisContext, Ulid>, ) -> Result<(), Self::Error>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
Source§

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
Source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
Source§

impl<Res, Args, Conn, Decode, Err> WaitForCompletion<Res> for RedisStorage<Args, Conn, Decode>
where Args: Unpin + Send + Sync + 'static, Conn: Clone + ConnectionLike + Send + Sync + 'static, Decode: Codec<Args, Compact = Vec<u8>, Error = Err> + Codec<Result<Res, String>, Compact = Vec<u8>, Error = Err> + Send + Sync + Unpin + 'static + Clone, Err: Into<BoxDynError> + Send + 'static, Res: Send + 'static,

Source§

type ResultStream = Pin<Box<dyn Stream<Item = Result<TaskResult<Res>, <RedisStorage<Args, Conn, Decode> as Backend>::Error>> + Send>>

The result stream type yielding task results
Source§

fn wait_for( &self, task_ids: impl IntoIterator<Item = TaskId<Self::IdType>>, ) -> Self::ResultStream

Wait for multiple tasks to complete, yielding results as they become available
Source§

async fn check_status( &self, task_ids: impl IntoIterator<Item = TaskId<Self::IdType>> + Send, ) -> Result<Vec<TaskResult<Res>>, Self::Error>

Check current status of tasks without waiting
Source§

fn wait_for_single(&self, task_id: TaskId<Self::IdType>) -> Self::ResultStream

Wait for a single task to complete, yielding its result

Auto Trait Implementations§

§

impl<Args, Conn, C> Freeze for RedisStorage<Args, Conn, C>
where Conn: Freeze,

§

impl<Args, Conn = ConnectionManager, C = JsonCodec<Vec<u8>>> !RefUnwindSafe for RedisStorage<Args, Conn, C>

§

impl<Args, Conn, C> Send for RedisStorage<Args, Conn, C>
where Conn: Send, Args: Send, C: Send,

§

impl<Args, Conn, C> Sync for RedisStorage<Args, Conn, C>
where Conn: Sync, Args: Sync, C: Sync,

§

impl<Args, Conn, C> Unpin for RedisStorage<Args, Conn, C>
where Conn: Unpin, Args: Unpin, C: Unpin,

§

impl<Args, Conn = ConnectionManager, C = JsonCodec<Vec<u8>>> !UnwindSafe for RedisStorage<Args, Conn, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, Item> SinkExt<Item> for T
where T: Sink<Item> + ?Sized,

Source§

fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
where F: FnMut(U) -> Fut, Fut: Future<Output = Result<Item, E>>, E: From<Self::Error>, Self: Sized,

Composes a function in front of the sink. Read more
Source§

fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
where F: FnMut(U) -> St, St: Stream<Item = Result<Item, Self::Error>>, Self: Sized,

Composes a function in front of the sink. Read more
Source§

fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
where F: FnOnce(Self::Error) -> E, Self: Sized,

Transforms the error returned by the sink.
Source§

fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
where Self: Sized, Self::Error: Into<E>,

Map this sink’s error to a different error type using the Into trait. Read more
Source§

fn buffer(self, capacity: usize) -> Buffer<Self, Item>
where Self: Sized,

Available on crate feature alloc only.
Adds a fixed-size buffer to the current sink. Read more
Source§

fn close(&mut self) -> Close<'_, Self, Item>
where Self: Unpin,

Close the sink.
Source§

fn fanout<Si>(self, other: Si) -> Fanout<Self, Si>
where Self: Sized, Item: Clone, Si: Sink<Item, Error = Self::Error>,

Fanout items to multiple sinks. Read more
Source§

fn flush(&mut self) -> Flush<'_, Self, Item>
where Self: Unpin,

Flush the sink, processing all pending items. Read more
Source§

fn send(&mut self, item: Item) -> Send<'_, Self, Item>
where Self: Unpin,

A future that completes after the given item has been fully processed into the sink, including flushing. Read more
Source§

fn feed(&mut self, item: Item) -> Feed<'_, Self, Item>
where Self: Unpin,

A future that completes after the given item has been received by the sink. Read more
Source§

fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St>
where St: TryStream<Ok = Item, Error = Self::Error> + Stream + Unpin + ?Sized, Self: Unpin,

A future that completes after the given stream has been fully processed into the sink, including flushing. Read more
Source§

fn left_sink<Si2>(self) -> Either<Self, Si2>
where Si2: Sink<Item, Error = Self::Error>, Self: Sized,

Wrap this sink in an Either sink, making it the left-hand variant of that Either. Read more
Source§

fn right_sink<Si1>(self) -> Either<Si1, Self>
where Si1: Sink<Item, Error = Self::Error>, Self: Sized,

Wrap this stream in an Either stream, making it the right-hand variant of that Either. Read more
Source§

fn poll_ready_unpin( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
where Self: Unpin,

A convenience method for calling Sink::poll_ready on Unpin sink types.
Source§

fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>
where Self: Unpin,

A convenience method for calling Sink::start_send on Unpin sink types.
Source§

fn poll_flush_unpin( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
where Self: Unpin,

A convenience method for calling Sink::poll_flush on Unpin sink types.
Source§

fn poll_close_unpin( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
where Self: Unpin,

A convenience method for calling Sink::poll_close on Unpin sink types.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<B, Args> Expose<Args> for B
where B: Backend<Args = Args> + Metrics + ListWorkers + ListQueues + ListAllTasks + ListTasks<Args> + TaskSink<Args>,