Skip to main content

Task

Trait Task 

Source
pub trait Task:
    Send
    + Sync
    + Serialize
    + DeserializeOwned
    + 'static {
    type Output: Serialize + DeserializeOwned + Send;

    const NAME: &'static str;
    const QUEUE: &'static str = "default";
    const MAX_RETRIES: u32 = 3;

    // Required method
    fn run<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 TaskContext,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Output, KojinError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn backoff() -> BackoffStrategy { ... }
    fn signature(&self) -> Signature { ... }
}
Expand description

A unit of work that can be enqueued and executed by a worker.

Required Associated Constants§

Source

const NAME: &'static str

Unique name used for routing. Must be stable across deploys.

Provided Associated Constants§

Source

const QUEUE: &'static str = "default"

Default queue name.

Source

const MAX_RETRIES: u32 = 3

Maximum number of retry attempts.

Required Associated Types§

Source

type Output: Serialize + DeserializeOwned + Send

The output type of the task.

Required Methods§

Source

fn run<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 TaskContext, ) -> Pin<Box<dyn Future<Output = Result<Self::Output, KojinError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Execute the task.

Provided Methods§

Source

fn backoff() -> BackoffStrategy

Backoff strategy for retries.

Source

fn signature(&self) -> Signature

Build a Signature from this task instance.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§