use crate::NextStep;
use std::{error::Error as StdError, result::Result as StdResult};
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("can't add task")]
AddTask(#[source] sqlx::Error),
#[error("can't serialize step: {1}")]
SerializeStep(#[source] serde_json::Error, String),
#[error(
"can't deserialize step (the task was likely changed between the scheduling and running of the step): {1}"
)]
DeserializeStep(#[source] serde_json::Error, String),
#[error("listener can't connect to the db")]
ListenerConnect(#[source] sqlx::Error),
#[error("can't start listening for notifications")]
ListenerListen(#[source] sqlx::Error),
#[error("listener can't receive notifications")]
ListenerReceive(#[source] sqlx::Error),
#[error("unreachable: worker semaphore is closed")]
UnreachableWorkerSemaphoreClosed(#[source] tokio::sync::AcquireError),
#[error("task lease expired before the worker could renew it")]
TaskLeaseExpired,
#[error("db error: {1}")]
Db(#[source] sqlx::Error, String),
}
pub type Result<T> = StdResult<T, Error>;
pub type StepError = Box<dyn StdError + 'static + Send + Sync>;
pub type StepResult<T> = StdResult<NextStep<T>, StepError>;