pub struct TaskContext<'a> { /* private fields */ }Expand description
Per-call execution context handed to AsyncFunctionHandler::execute.
Borrows the message and datalogic engine for the duration of the handler
call; collects Change entries that the workflow executor folds into the
audit trail when the handler returns. Drop semantics are trivial — there
is nothing to flush; the executor extracts the buffered changes via
into_changes().
Implementations§
Source§impl<'a> TaskContext<'a>
impl<'a> TaskContext<'a>
Sourcepub fn new(
message: &'a mut Message,
datalogic: &'a Arc<DatalogicEngine>,
) -> Self
pub fn new( message: &'a mut Message, datalogic: &'a Arc<DatalogicEngine>, ) -> Self
Construct a new context. Mostly engine-internal — handlers receive a
pre-built &mut TaskContext from the executor — but exposed pub so
tests and benchmarks can drive AsyncFunctionHandler::execute
directly without going through Engine::process_message.
Sourcepub fn message(&self) -> &Message
pub fn message(&self) -> &Message
Borrow the message under processing. Use this when you need to inspect
the message id, payload, or audit trail; for reading and mutating the
data / metadata / temp_data context, prefer the typed helpers on
TaskContext itself.
Sourcepub fn message_mut(&mut self) -> &mut Message
pub fn message_mut(&mut self) -> &mut Message
Mutable access to the message. Prefer the typed helpers (set,
add_error) over poking at message.context directly — direct
mutations bypass the audit trail.
Sourcepub fn datalogic(&self) -> &Arc<DatalogicEngine>
pub fn datalogic(&self) -> &Arc<DatalogicEngine>
Shared datalogic engine, in case the handler needs to evaluate ad-hoc JSONLogic. Most handlers can ignore this argument.
Sourcepub fn data(&self) -> &OwnedDataValue
pub fn data(&self) -> &OwnedDataValue
Read-only view of data. Returns &OwnedDataValue::Null if missing
(mirrors the Index fallback semantics of serde_json::Value).
Sourcepub fn metadata(&self) -> &OwnedDataValue
pub fn metadata(&self) -> &OwnedDataValue
Read-only view of metadata.
Sourcepub fn temp_data(&self) -> &OwnedDataValue
pub fn temp_data(&self) -> &OwnedDataValue
Read-only view of temp_data.
Sourcepub fn get(&self, path: &str) -> Option<&OwnedDataValue>
pub fn get(&self, path: &str) -> Option<&OwnedDataValue>
Look up a value by dot-path against the full context tree (rooted at
the unified {data, metadata, temp_data} object). Returns None if
the path doesn’t resolve.
Use the same path syntax as JSONLogic: "data.user.name",
"temp_data.items.0", "metadata.progress.status_code".
Sourcepub fn set(&mut self, path: &str, value: OwnedDataValue)
pub fn set(&mut self, path: &str, value: OwnedDataValue)
Set a value at a dot-path on the context. Records a Change on the
audit trail when message.capture_changes is true; otherwise the
write happens but no audit entry is buffered.
Intermediate objects/arrays are created on demand; see
crate::engine::utils::set_nested_value for the exact semantics
(numeric segments → arrays, # prefix → escaped object key, etc.).
Sourcepub fn set_json(&mut self, path: &str, value: &JsonValue)
pub fn set_json(&mut self, path: &str, value: &JsonValue)
Same as Self::set but accepts a serde_json::Value (bridges
through OwnedDataValue::from). Convenience for handlers that
already speak serde_json::Value.
Sourcepub fn add_error(&mut self, error: ErrorInfo)
pub fn add_error(&mut self, error: ErrorInfo)
Append an error to message.errors. Convenience for
ctx.message_mut().add_error(...).
Sourcepub fn into_changes(self) -> Vec<Change>
pub fn into_changes(self) -> Vec<Change>
Drain the accumulated changes. The workflow executor calls this after the handler returns to fold them into the audit trail; tests and benchmarks driving the trait directly can use it to inspect what the handler buffered.