Struct fang::asynk::async_queue::AsyncQueue
source · pub struct AsyncQueue<Tls>where
Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
<Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
<Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
<<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,{ /* private fields */ }
Expand description
An async queue that can be used to enqueue tasks.
It uses a PostgreSQL storage. It must be connected to perform any operation.
To connect an AsyncQueue
to PostgreSQL database call the connect
method.
A Queue can be created with the TypedBuilder.
let mut queue = AsyncQueue::builder()
.uri("postgres://postgres:postgres@localhost/fang")
.max_pool_size(max_pool_size)
.build();
Implementations§
source§impl<Tls> AsyncQueue<Tls>where
Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
<Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
<Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
<<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
impl<Tls> AsyncQueue<Tls>where Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static, <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync, <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send, <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
source§impl<Tls> AsyncQueue<Tls>where
Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
<Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
<Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
<<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
impl<Tls> AsyncQueue<Tls>where Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static, <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync, <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send, <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
sourcepub fn check_if_connection(&self) -> Result<(), AsyncQueueError>
pub fn check_if_connection(&self) -> Result<(), AsyncQueueError>
Check if the connection with db is established
sourcepub async fn connect(&mut self, tls: Tls) -> Result<(), AsyncQueueError>
pub async fn connect(&mut self, tls: Tls) -> Result<(), AsyncQueueError>
Connect to the db if not connected
Trait Implementations§
source§impl<Tls> AsyncQueueable for AsyncQueue<Tls>where
Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
<Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
<Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
<<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
impl<Tls> AsyncQueueable for AsyncQueue<Tls>where Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static, <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync, <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send, <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
source§fn find_task_by_id<'life0, 'async_trait>(
&'life0 mut self,
id: Uuid
) -> Pin<Box<dyn Future<Output = Result<Task, AsyncQueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn find_task_by_id<'life0, 'async_trait>( &'life0 mut self, id: Uuid ) -> Pin<Box<dyn Future<Output = Result<Task, AsyncQueueError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Retrieve a task from storage by its
id
.source§fn fetch_and_touch_task<'life0, 'async_trait>(
&'life0 mut self,
task_type: Option<String>
) -> Pin<Box<dyn Future<Output = Result<Option<Task>, AsyncQueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn fetch_and_touch_task<'life0, 'async_trait>( &'life0 mut self, task_type: Option<String> ) -> Pin<Box<dyn Future<Output = Result<Option<Task>, AsyncQueueError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
This method should retrieve one task of the
task_type
type. If task_type
is None
it will try to
fetch a task of the type common
. After fetching it should update the state of the task to
FangTaskState::InProgress
.source§fn insert_task<'life0, 'life1, 'async_trait>(
&'life0 mut self,
task: &'life1 dyn AsyncRunnable
) -> Pin<Box<dyn Future<Output = Result<Task, AsyncQueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn insert_task<'life0, 'life1, 'async_trait>( &'life0 mut self, task: &'life1 dyn AsyncRunnable ) -> Pin<Box<dyn Future<Output = Result<Task, AsyncQueueError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Enqueue a task to the queue, The task will be executed as soon as possible by the worker of the same type
created by an AsyncWorkerPool.
source§fn schedule_task<'life0, 'life1, 'async_trait>(
&'life0 mut self,
task: &'life1 dyn AsyncRunnable
) -> Pin<Box<dyn Future<Output = Result<Task, AsyncQueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn schedule_task<'life0, 'life1, 'async_trait>( &'life0 mut self, task: &'life1 dyn AsyncRunnable ) -> Pin<Box<dyn Future<Output = Result<Task, AsyncQueueError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Schedule a task.
source§fn remove_all_tasks<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<u64, AsyncQueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn remove_all_tasks<'life0, 'async_trait>( &'life0 mut self ) -> Pin<Box<dyn Future<Output = Result<u64, AsyncQueueError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
The method will remove all tasks from the queue
source§fn remove_all_scheduled_tasks<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<u64, AsyncQueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn remove_all_scheduled_tasks<'life0, 'async_trait>( &'life0 mut self ) -> Pin<Box<dyn Future<Output = Result<u64, AsyncQueueError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Remove all tasks that are scheduled in the future.
source§fn remove_task<'life0, 'async_trait>(
&'life0 mut self,
id: Uuid
) -> Pin<Box<dyn Future<Output = Result<u64, AsyncQueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn remove_task<'life0, 'async_trait>( &'life0 mut self, id: Uuid ) -> Pin<Box<dyn Future<Output = Result<u64, AsyncQueueError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Remove a task by its id.
source§fn remove_task_by_metadata<'life0, 'life1, 'async_trait>(
&'life0 mut self,
task: &'life1 dyn AsyncRunnable
) -> Pin<Box<dyn Future<Output = Result<u64, AsyncQueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn remove_task_by_metadata<'life0, 'life1, 'async_trait>( &'life0 mut self, task: &'life1 dyn AsyncRunnable ) -> Pin<Box<dyn Future<Output = Result<u64, AsyncQueueError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Remove a task by its metadata (struct fields values)
source§fn remove_tasks_type<'life0, 'life1, 'async_trait>(
&'life0 mut self,
task_type: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<u64, AsyncQueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn remove_tasks_type<'life0, 'life1, 'async_trait>( &'life0 mut self, task_type: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<u64, AsyncQueueError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Removes all tasks that have the specified
task_type
.source§fn update_task_state<'life0, 'async_trait>(
&'life0 mut self,
task: Task,
state: FangTaskState
) -> Pin<Box<dyn Future<Output = Result<Task, AsyncQueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn update_task_state<'life0, 'async_trait>( &'life0 mut self, task: Task, state: FangTaskState ) -> Pin<Box<dyn Future<Output = Result<Task, AsyncQueueError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Update the state field of the specified task
See the
FangTaskState
enum for possible states.source§fn fail_task<'life0, 'life1, 'async_trait>(
&'life0 mut self,
task: Task,
error_message: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Task, AsyncQueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn fail_task<'life0, 'life1, 'async_trait>( &'life0 mut self, task: Task, error_message: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<Task, AsyncQueueError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Update the state of a task to
FangTaskState::Failed
and set an error_message.fn schedule_retry<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, task: &'life1 Task, backoff_seconds: u32, error: &'life2 str ) -> Pin<Box<dyn Future<Output = Result<Task, AsyncQueueError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,
source§impl<Tls> Clone for AsyncQueue<Tls>where
Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + Clone,
<Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
<Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
<<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
impl<Tls> Clone for AsyncQueue<Tls>where Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + Clone, <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync, <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send, <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
source§fn clone(&self) -> AsyncQueue<Tls>
fn clone(&self) -> AsyncQueue<Tls>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<Tls> Debug for AsyncQueue<Tls>where
Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + Debug,
<Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
<Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
<<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
impl<Tls> Debug for AsyncQueue<Tls>where Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + Debug, <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync, <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send, <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
Auto Trait Implementations§
impl<Tls> !RefUnwindSafe for AsyncQueue<Tls>
impl<Tls> Send for AsyncQueue<Tls>
impl<Tls> Sync for AsyncQueue<Tls>
impl<Tls> Unpin for AsyncQueue<Tls>
impl<Tls> !UnwindSafe for AsyncQueue<Tls>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoSql for T
impl<T> IntoSql for T
source§fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
T: SqlType + TypedExpressionType,
fn into_sql<T>(self) -> Self::Expressionwhere Self: AsExpression<T> + Sized, T: SqlType + TypedExpressionType,
Convert
self
to an expression for Diesel’s query builder. Read moresource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
T: SqlType + TypedExpressionType,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,
Convert
&self
to an expression for Diesel’s query builder. Read more