pub trait CustomTaskHandler: Send + Sync {
// Required methods
fn task_type(&self) -> &str;
fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>(
&'life0 self,
task_name: &'life1 str,
task_type: &'life2 str,
task_config: &'life3 Value,
input: &'life4 Value,
context: &'life5 HandlerContext,
) -> Pin<Box<dyn Future<Output = WorkflowResult<Value>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
'life5: 'async_trait;
}Expand description
Handler for custom/extension task types.
Implement this trait to provide support for custom task types that are
not part of the built-in Serverless Workflow specification.
Register handlers with WorkflowRunner::with_custom_task_handler().
§Example
use async_trait::async_trait;
use serde_json::Value;
use swf_runtime::{CustomTaskHandler, HandlerContext, WorkflowResult};
struct UppercaseHandler;
#[async_trait]
impl CustomTaskHandler for UppercaseHandler {
fn task_type(&self) -> &str { "uppercase" }
async fn handle(
&self,
task_name: &str,
task_type: &str,
task_config: &Value,
input: &Value,
context: &HandlerContext,
) -> WorkflowResult<Value> {
let text = input["text"].as_str().unwrap_or("");
Ok(serde_json::json!({ "result": text.to_uppercase() }))
}
}Required Methods§
Sourcefn task_type(&self) -> &str
fn task_type(&self) -> &str
Returns the custom task type this handler supports (e.g., “myCustomTask”)
Sourcefn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>(
&'life0 self,
task_name: &'life1 str,
task_type: &'life2 str,
task_config: &'life3 Value,
input: &'life4 Value,
context: &'life5 HandlerContext,
) -> Pin<Box<dyn Future<Output = WorkflowResult<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
'life5: 'async_trait,
fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>(
&'life0 self,
task_name: &'life1 str,
task_type: &'life2 str,
task_config: &'life3 Value,
input: &'life4 Value,
context: &'life5 HandlerContext,
) -> Pin<Box<dyn Future<Output = WorkflowResult<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
'life5: 'async_trait,
Executes the custom task with the given configuration, input, and workflow context.