Skip to main content

Job

Derive Macro Job 

Source
#[derive(Job)]
{
    // Attributes available to this derive:
    #[job]
}
Expand description

Implement queuey_core::Job for a struct or enum.

The type must also be Serialize + DeserializeOwned; add those derives yourself, this macro never generates them.

§Attributes

#[job(
    queue = AppQueues::Emails,         // required; Job::Queue = AppQueues
    name = "emails.send",              // default: module_path!() + "::" + type name
    retry(max_attempts = 5),           // optional; generates retry_policy()
    crate = "queuey",         // path to the core crate re-export
)]

queue is a path with at least two segments: the last segment is the variant (Job::QUEUE) and everything before it is the queue set type (Job::Queue).

§Example

use queuey_core::Job;
use queuey_macros::{Job, Queues};
use serde::{Deserialize, Serialize};

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

#[derive(Job, Serialize, Deserialize)]
#[job(queue = AppQueues::Emails, retry(max_attempts = 5, backoff = "fixed", delay = "2s"))]
struct SendEmail {
    to: String,
}

assert_eq!(SendEmail::QUEUE, AppQueues::Emails);
assert!(SendEmail::retry_policy().is_some());

§Errors

Compile errors, spanned at the offending token, are produced for: a missing queue key, a queue path with a single segment, a generic type, unknown or duplicated attribute keys, and every retry(...) error listed on Queues.