Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ where
/// Output type (must be JSON-serializable)
type Output: Serialize + DeserializeOwned + Send;

/// Validate the parameters for this task.
/// This is called before spawning the task, to allow us to catch errors early.
/// By default, this just tries to deserialize the parameters into the `Self::Params` type.
fn validate_params(&self, params: JsonValue) -> Result<(), TaskError> {
let _typed_params: Self::Params = serde_json::from_value(params)?;
Ok(())
}

/// Execute the task logic.
///
/// Return `Ok(output)` on success, or `Err(TaskError)` on failure.
Expand Down Expand Up @@ -144,9 +152,7 @@ where
}

fn validate_params(&self, params: JsonValue) -> Result<(), TaskError> {
// For now, just deserialize
let _typed_params: T::Params = serde_json::from_value(params)?;
Ok(())
self.0.validate_params(params)
}

async fn execute(
Expand Down