Skip to main content

TaskHandlers

Trait TaskHandlers 

Source
pub trait TaskHandlers<Context>: MaybeSend + MaybeSync {
    type Error: RetryableError + NeedsDbReconnect + From<StorageError> + Error + MaybeSend + MaybeSync + 'static;

    // Required method
    fn dispatch<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        context: &'life1 Context,
        task: &'life2 Task,
    ) -> Pin<Box<dyn Future<Output = Result<TaskOutcome, Self::Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn on_start(&self, _context: &Context) -> Result<(), Self::Error> { ... }
    fn on_events(
        &self,
        _context: &Context,
        _events: &[EventEnvelope<InternalEvent>],
    ) -> Result<(), Self::Error> { ... }
}
Expand description

The handlers a TaskWorker runs. The runner owns each task’s schedule: expiry, attempts, backoff and rate-limit holds. The handlers run one row.

Required Associated Types§

Source

type Error: RetryableError + NeedsDbReconnect + From<StorageError> + Error + MaybeSend + MaybeSync + 'static

The error of a failed run. The runner reads its rate-limit delay and its reconnect signal, and reports its own storage failures as this type.

Required Methods§

Source

fn dispatch<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, context: &'life1 Context, task: &'life2 Task, ) -> Pin<Box<dyn Future<Output = Result<TaskOutcome, Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Run one due task. Gets the whole row: handlers use task.id, for example to delete it.

Provided Methods§

Source

fn on_start(&self, _context: &Context) -> Result<(), Self::Error>

Runs when the runner starts, before it reads a task.

Source

fn on_events( &self, _context: &Context, _events: &[EventEnvelope<InternalEvent>], ) -> Result<(), Self::Error>

Runs once for each batch of events the runner reads that holds an event other than its own TaskScheduled, and gets the whole batch. Public events such as ConsentChanged and ArchiveRestored arrive here.

Implementors§