1use thiserror::Error;
4
5pub type JobResult<T> = Result<T, JobError>;
7
8#[derive(Debug, Error)]
10pub enum JobError {
11 #[error("job execution failed: {0}")]
13 ExecutionFailed(String),
14
15 #[error("job timed out after {0:?}")]
17 Timeout(std::time::Duration),
18
19 #[error("job failed after {0} retries")]
21 MaxRetriesExceeded(u32),
22
23 #[error("serialization error: {0}")]
25 SerializationError(#[from] serde_json::Error),
26
27 #[cfg(feature = "redis")]
29 #[error("redis error: {0}")]
30 RedisError(#[from] redis::RedisError),
31
32 #[error("job not found: {0}")]
34 NotFound(String),
35
36 #[error("job queue is full (max: {0})")]
38 QueueFull(usize),
39
40 #[error("job agent not available")]
42 AgentUnavailable,
43
44 #[error("{0}")]
46 Other(String),
47}
48
49impl From<String> for JobError {
50 fn from(s: String) -> Self {
51 Self::ExecutionFailed(s)
52 }
53}
54
55impl From<&str> for JobError {
56 fn from(s: &str) -> Self {
57 Self::ExecutionFailed(s.to_string())
58 }
59}
60
61impl From<anyhow::Error> for JobError {
62 fn from(err: anyhow::Error) -> Self {
63 Self::ExecutionFailed(err.to_string())
64 }
65}