use thiserror::Error;
pub type JobResult<T> = Result<T, JobError>;
#[derive(Debug, Error)]
pub enum JobError {
#[error("job execution failed: {0}")]
ExecutionFailed(String),
#[error("job timed out after {0:?}")]
Timeout(std::time::Duration),
#[error("job failed after {0} retries")]
MaxRetriesExceeded(u32),
#[error("serialization error: {0}")]
SerializationError(#[from] serde_json::Error),
#[cfg(feature = "redis")]
#[error("redis error: {0}")]
RedisError(#[from] redis::RedisError),
#[error("job not found: {0}")]
NotFound(String),
#[error("job queue is full (max: {0})")]
QueueFull(usize),
#[error("job agent not available")]
AgentUnavailable,
#[error("{0}")]
Other(String),
}
impl From<String> for JobError {
fn from(s: String) -> Self {
Self::ExecutionFailed(s)
}
}
impl From<&str> for JobError {
fn from(s: &str) -> Self {
Self::ExecutionFailed(s.to_string())
}
}
impl From<anyhow::Error> for JobError {
fn from(err: anyhow::Error) -> Self {
Self::ExecutionFailed(err.to_string())
}
}