persistent_scheduler::core::task

Trait Task

Source
pub trait Task:
    Serialize
    + DeserializeOwned
    + 'static {
    const TASK_KEY: &'static str;
    const TASK_QUEUE: &'static str;
    const TASK_KIND: TaskKind;
    const SCHEDULE: Option<&'static str> = None;
    const TIMEZONE: Option<&'static str> = None;
    const REPEAT_INTERVAL: Option<u32> = None;
    const RETRY_POLICY: RetryPolicy = _;
    const DELAY_SECONDS: u32 = 3u32;

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

    // Provided methods
    fn validate(&self) -> Result<(), String> { ... }
    fn new_meta(&self) -> 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.

Source

const TASK_KIND: TaskKind

The type of task being defined.

This specifies the task behavior and can be one of the TaskKind variants.

Provided Associated Constants§

Source

const SCHEDULE: Option<&'static str> = None

Schedule expression for Cron tasks.

This field is required if TASK_KIND is TaskKind::Cron. It defines the schedule on which the task should run.

Source

const TIMEZONE: Option<&'static str> = None

Timezone for the schedule expression.

This is required for TaskKind::Cron and specifies the timezone for the cron schedule.

Source

const REPEAT_INTERVAL: Option<u32> = None

Repeat interval for Repeat tasks, in seconds.

This field is required if TASK_KIND is TaskKind::Repeat. It defines the interval between consecutive executions of the task.

Source

const RETRY_POLICY: RetryPolicy = _

The retry policy for this task.

Defines the strategy and maximum retry attempts in case of failure. Default is exponential backoff with a base of 2 and a maximum of 5 retries.

Source

const DELAY_SECONDS: u32 = 3u32

Delay before executing a Once task, in seconds.

Specifies the delay before starting a Once task after it is scheduled.

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 validate(&self) -> 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) -> 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§