pub struct HandlerContext { /* private fields */ }Expand description
Read-only snapshot of workflow context variables available to task handlers.
Provides access to $context, $secret, $workflow, and other runtime variables
that were previously inaccessible from custom handlers.
§Example
use async_trait::async_trait;
use serde_json::Value;
use swf_runtime::{CustomTaskHandler, HandlerContext, WorkflowResult};
struct SmartHandler;
#[async_trait]
impl CustomTaskHandler for SmartHandler {
fn task_type(&self) -> &str { "smart" }
async fn handle(
&self,
task_name: &str,
task_type: &str,
task_config: &Value,
input: &Value,
context: &HandlerContext,
) -> WorkflowResult<Value> {
// Access $context to read workflow state
let preferred = context.context().get("provider").and_then(|v| v.as_str());
// Access $secret for credentials
let api_key = context.secret().and_then(|s| s.get("API_KEY")).and_then(|v| v.as_str());
Ok(input.clone())
}
}Implementations§
Source§impl HandlerContext
impl HandlerContext
Sourcepub fn context(&self) -> &Value
pub fn context(&self) -> &Value
Returns the $context value (workflow instance state set by export.as)
Sourcepub fn secret(&self) -> Option<&Value>
pub fn secret(&self) -> Option<&Value>
Returns the $secret value (all resolved secrets), if a secret manager is configured
Returns the $authorization value (set after HTTP authentication), if any
Trait Implementations§
Source§impl Clone for HandlerContext
impl Clone for HandlerContext
Source§fn clone(&self) -> HandlerContext
fn clone(&self) -> HandlerContext
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for HandlerContext
impl RefUnwindSafe for HandlerContext
impl Send for HandlerContext
impl Sync for HandlerContext
impl Unpin for HandlerContext
impl UnsafeUnpin for HandlerContext
impl UnwindSafe for HandlerContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more