pub trait Job:
Send
+ Serialize
+ Deserialize {
// Required method
fn handle(self: Box<Self>) -> Pin<Box<dyn Future<Output = Result<()>>>>;
// Provided method
fn queue_binding(&self) -> &'static str { ... }
}Expand description
Trait that every job struct must implement.
Use #[celerix::job] on your impl Job for T block.
Jobs are automatically registered via typetag — no manual
registration needed. The queue consumer will deserialize and
dispatch to the right handler automatically.
§Example
ⓘ
#[derive(Serialize, Deserialize)]
struct SendEmail {
to: String,
subject: String,
}
#[celerix::job]
impl Job for SendEmail {
fn handle(self: Box<Self>) -> Pin<Box<dyn Future<Output = worker::Result<()>>>> {
Box::pin(async move {
worker::console_log!("Sending email to {}", self.to);
Ok(())
})
}
}
// Dispatch:
SendEmail { to: "a@b.com".into() }.dispatch(&env).await?;Required Methods§
Provided Methods§
Sourcefn queue_binding(&self) -> &'static str
fn queue_binding(&self) -> &'static str
The queue binding name this job targets.
Defaults to “QUEUE” which maps to the auto-generated
{PROJECT_NAME}_QUEUE in wrangler.toml.
Override this to send to a different queue.