Trait fang::asynk::async_runnable::AsyncRunnable
source · 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§
Provided Methods§
sourcefn task_type(&self) -> String
fn task_type(&self) -> String
Define the type of the task.
The common
task type is used by default
sourcefn uniq(&self) -> bool
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.
sourcefn cron(&self) -> Option<Scheduled>
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.
sourcefn max_retries(&self) -> i32
fn max_retries(&self) -> i32
Define the maximum number of retries the task will be retried. By default the number of retries is 20.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Box<dyn AsyncRunnable>
impl<'de> Deserialize<'de> for Box<dyn AsyncRunnable>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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>
impl<'de> Deserialize<'de> for Box<dyn AsyncRunnable + Send>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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>
impl<'de> Deserialize<'de> for Box<dyn AsyncRunnable + Send + Sync>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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>
impl<'de> Deserialize<'de> for Box<dyn AsyncRunnable + Sync>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more