use graphile_worker_ctx::WorkerContext;
use serde_json::Value;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
pub type TaskHandlerFn = Arc<
dyn Fn(WorkerContext) -> Pin<Box<dyn Future<Output = TaskHandlerOutcome> + Send>> + Send + Sync,
>;
#[derive(Debug, Clone, PartialEq)]
pub enum TaskHandlerOutcome {
Complete,
Failed {
error: String,
replacement_payload: Option<Value>,
},
}
impl TaskHandlerOutcome {
pub fn failed(error: impl Into<String>) -> Self {
Self::Failed {
error: error.into(),
replacement_payload: None,
}
}
pub fn failed_with_replacement(
error: impl Into<String>,
replacement_payload: impl Into<Value>,
) -> Self {
Self::Failed {
error: error.into(),
replacement_payload: Some(replacement_payload.into()),
}
}
}