Skip to main content

Job

Trait Job 

Source
pub trait Job:
    Serialize
    + DeserializeOwned
    + Send
    + Sync
    + 'static {
    type Queue: QueueSet;

    const NAME: &'static str;
    const QUEUE: Self::Queue;

    // Provided method
    fn retry_policy() -> Option<RetryPolicy> { ... }
}
Expand description

A unit of work. Normally implemented via #[derive(Job)] from the macros crate; the hand-written equivalent is:

use queuey_core::{Job, QueueConfig, QueueSet, RetryPolicy};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum AppQueues { Emails }

impl QueueSet for AppQueues {
    fn all() -> &'static [Self] { &[AppQueues::Emails] }
    fn name(&self) -> &'static str { "emails" }
    fn config(&self) -> QueueConfig { QueueConfig::new(self.name()) }
}

#[derive(Serialize, Deserialize)]
struct SendEmail { to: String }

impl Job for SendEmail {
    type Queue = AppQueues;
    const NAME: &'static str = "SendEmail";
    const QUEUE: AppQueues = AppQueues::Emails;
    fn retry_policy() -> Option<RetryPolicy> { Some(RetryPolicy::exponential(5)) }
}

assert_eq!(SendEmail::QUEUE.name(), "emails");

Required Associated Constants§

Source

const NAME: &'static str

Unique, stable identifier for this job type. Used for routing to the right handler. Defaults to the fully-qualified type path via the derive macro.

Source

const QUEUE: Self::Queue

The queue (variant) this job is published to and consumed from.

Required Associated Types§

Source

type Queue: QueueSet

The queue set this job belongs to.

Provided Methods§

Source

fn retry_policy() -> Option<RetryPolicy>

Per-job retry override. None means “use the queue’s policy”.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§