Trait Task

Source
pub trait Task:
    Serialize
    + DeserializeOwned
    + 'static {
    const TASK_KEY: &'static str;
    const TASK_QUEUE: &'static str;

    // Required method
    fn run(self) -> TaskFuture;

    // Provided methods
    fn retry_policy(&self) -> RetryPolicy { ... }
    fn delay_seconds(&self) -> u32 { ... }
    fn validate(&self, kind: &TaskKind) -> Result<(), String> { ... }
    fn new_meta(&self, kind: TaskKind) -> TaskMeta { ... }
}

Required Associated Constants§

Source

const TASK_KEY: &'static str

A unique identifier for this task.

This name must be unique and is used to identify the task.

Source

const TASK_QUEUE: &'static str

The default queue associated with this task.

This can be overridden at the individual task level. If a non-existent queue is specified, the task will not be processed.

Required Methods§

Source

fn run(self) -> TaskFuture

Executes the task with the given parameters.

Contains the logic required to perform the task. Takes parameters of type Self::Params that can be used during execution.

Provided Methods§

Source

fn retry_policy(&self) -> RetryPolicy

Returns the retry policy for this task instance. Default is exponential backoff with base 2 and max 3 retries.

Source

fn delay_seconds(&self) -> u32

Returns the delay in seconds before executing a Once task. Default is 3 seconds.

Source

fn validate(&self, kind: &TaskKind) -> Result<(), String>

Validates the parameters based on the task type.

Checks that the necessary fields for the specific TaskKind are provided.

Source

fn new_meta(&self, kind: TaskKind) -> TaskMeta

Creates a new metadata entry for the task.

This method generates a TaskMetaEntity instance based on the task’s properties. It validates required fields and panics if validation fails.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§