Skip to main content

Job

Trait Job 

Source
pub trait Job:
    Send
    + Serialize
    + Deserialize {
    // Required method
    fn handle(
        self: Box<Self>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>>>>;

    // 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§

Source

fn handle(self: Box<Self>) -> Pin<Box<dyn Future<Output = Result<(), Error>>>>

Execute the job.

Provided Methods§

Source

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.

Trait Implementations§

Source§

impl<'de> Deserialize<'de> for Box<dyn Job>

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Box<dyn Job>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'de> Deserialize<'de> for Box<dyn Job + Send>

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Box<dyn Job + Send>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'typetag> Serialize for dyn Job + 'typetag

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'typetag> Serialize for dyn Job + Send + 'typetag

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'typetag> Serialize for dyn Job + Send + Sync + 'typetag

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'typetag> Serialize for dyn Job + Sync + 'typetag

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Implementors§