pub trait AsyncRunnable: Send + Sync + Serialize + Deserialize {
    // Required method
    fn run<'life0, 'life1, 'async_trait>(
        &'life0 self,
        client: &'life1 mut dyn AsyncQueueable
    ) -> Pin<Box<dyn Future<Output = Result<(), FangError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn task_type(&self) -> String { ... }
    fn uniq(&self) -> bool { ... }
    fn cron(&self) -> Option<Scheduled> { ... }
    fn max_retries(&self) -> i32 { ... }
    fn backoff(&self, attempt: u32) -> u32 { ... }
}
Expand description

Implement this trait to run your custom tasks.

Required Methods§

source

fn run<'life0, 'life1, 'async_trait>( &'life0 self, client: &'life1 mut dyn AsyncQueueable ) -> Pin<Box<dyn Future<Output = Result<(), FangError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute the task. This method should define its logic

Provided Methods§

source

fn task_type(&self) -> String

Define the type of the task. The common task type is used by default

source

fn uniq(&self) -> bool

If set to true, no new tasks with the same metadata will be inserted By default it is set to false.

source

fn cron(&self) -> Option<Scheduled>

This method defines if a task is periodic or it should be executed once in the future.

Be careful it works only with the UTC timezone.

Example:

 fn cron(&self) -> Option<Scheduled> {
     let expression = "0/20 * * * Aug-Sep * 2022/1";
     Some(Scheduled::CronPattern(expression.to_string()))
 }

In order to schedule a task once, use the Scheduled::ScheduleOnce enum variant.

source

fn max_retries(&self) -> i32

Define the maximum number of retries the task will be retried. By default the number of retries is 20.

source

fn backoff(&self, attempt: u32) -> u32

Define the backoff mode By default, it is exponential, 2^(attempt)

Trait Implementations§

source§

impl<'de> Deserialize<'de> for Box<dyn AsyncRunnable>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'de> Deserialize<'de> for Box<dyn AsyncRunnable + Send>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'de> Deserialize<'de> for Box<dyn AsyncRunnable + Send + Sync>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'de> Deserialize<'de> for Box<dyn AsyncRunnable + Sync>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'typetag> Serialize for dyn AsyncRunnable + 'typetag

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'typetag> Serialize for dyn AsyncRunnable + Send + 'typetag

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'typetag> Serialize for dyn AsyncRunnable + Send + Sync + 'typetag

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'typetag> Serialize for dyn AsyncRunnable + Sync + 'typetag

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Strictest for dyn AsyncRunnable

Implementors§