use crate::core::Xid;
use async_trait::async_trait;
use std::convert::Infallible;
use thiserror::Error;
#[async_trait]
pub trait JobProcessor: Send + Sync {
type Payload: Send;
type Error: Send;
async fn handle(&self, jid: Xid, payload: Self::Payload) -> Result<(), Self::Error>;
fn max_retries(&self) -> u32 {
0
}
fn name() -> &'static str
where
Self: Sized;
}
#[derive(Error, Debug)]
pub enum JobError {
#[error("Failed to deserialize job context")]
DecodeError {
#[from]
source: bincode::error::DecodeError,
},
#[error(transparent)]
Other(#[from] anyhow::Error),
}
impl From<Infallible> for JobError {
fn from(_: Infallible) -> Self {
unreachable!();
}
}