49 lines
1.7 KiB
Rust
49 lines
1.7 KiB
Rust
use thiserror::Error;
|
|
|
|
/// An error that can happen during executing of tasks
|
|
#[derive(Debug)]
|
|
pub struct FangError {
|
|
/// A description of an error
|
|
pub description: String,
|
|
}
|
|
|
|
/// List of error types that can occur while working with cron schedules.
|
|
#[derive(Debug, Error)]
|
|
pub enum CronError {
|
|
/// A problem occured during cron schedule parsing.
|
|
#[error(transparent)]
|
|
LibraryError(#[from] cron::error::Error),
|
|
/// [`Scheduled`] enum variant is not provided
|
|
#[error("You have to implement method `cron()` in your AsyncRunnable")]
|
|
TaskNotSchedulableError,
|
|
/// The next execution can not be determined using the current [`Scheduled::CronPattern`]
|
|
#[error("No timestamps match with this cron pattern")]
|
|
NoTimestampsError,
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum AsyncQueueError {
|
|
#[error(transparent)]
|
|
PgError(#[from] diesel::result::Error),
|
|
#[error(transparent)]
|
|
SerdeError(#[from] serde_json::Error),
|
|
#[error(transparent)]
|
|
CronError(#[from] CronError),
|
|
#[error("returned invalid result (expected {expected:?}, found {found:?})")]
|
|
ResultError { expected: u64, found: u64 },
|
|
#[error(
|
|
"AsyncQueue is not connected :( , call connect() method first and then perform operations"
|
|
)]
|
|
NotConnectedError,
|
|
#[error("Can not convert `std::time::Duration` to `chrono::Duration`")]
|
|
TimeError,
|
|
#[error("Can not perform this operation if task is not uniq, please check its definition in impl AsyncRunnable")]
|
|
TaskNotUniqError,
|
|
}
|
|
|
|
impl From<cron::error::Error> for AsyncQueueError {
|
|
fn from(error: cron::error::Error) -> Self {
|
|
AsyncQueueError::CronError(CronError::LibraryError(error))
|
|
}
|
|
}
|