Skip to content

Commit 3884f0d

Browse files
authored
Move 'validate_params' into Task trait (#72)
This allows the implementation to be overridne by consumers of durable
1 parent 5e0e786 commit 3884f0d

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/task.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ where
7878
/// Output type (must be JSON-serializable)
7979
type Output: Serialize + DeserializeOwned + Send;
8080

81+
/// Validate the parameters for this task.
82+
/// This is called before spawning the task, to allow us to catch errors early.
83+
/// By default, this just tries to deserialize the parameters into the `Self::Params` type.
84+
fn validate_params(&self, params: JsonValue) -> Result<(), TaskError> {
85+
let _typed_params: Self::Params = serde_json::from_value(params)?;
86+
Ok(())
87+
}
88+
8189
/// Execute the task logic.
8290
///
8391
/// Return `Ok(output)` on success, or `Err(TaskError)` on failure.
@@ -144,9 +152,7 @@ where
144152
}
145153

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

152158
async fn execute(

0 commit comments

Comments
 (0)