pub struct Context { /* private fields */ }Expand description
The context object is used to interact with the Hatchet API from within a task.
Implementations§
Source§impl Context
impl Context
Sourcepub async fn parent_output(
&self,
parent_step_name: &str,
) -> Result<Value, HatchetError>
pub async fn parent_output( &self, parent_step_name: &str, ) -> Result<Value, HatchetError>
Get the output of a parent task in a DAG.
ⓘ
let task = hatchet.task("my-task", |_input: EmptyModel, ctx: Context| async move {
let parent_output = ctx.parent_output("parent_task").await.unwrap();
Ok(EmptyModel)
});pub async fn filter_payload(&self) -> Result<Value, HatchetError>
Sourcepub async fn log(&self, message: &str) -> Result<(), HatchetError>
pub async fn log(&self, message: &str) -> Result<(), HatchetError>
Log a line to the Hatchet API. This will send the log line to the Hatchet API and return immediately.
ⓘ
use hatchet_sdk::{Hatchet, EmptyModel};
let hatchet = Hatchet::from_env().await.unwrap();
let task = hatchet.task("my-task", |_input: EmptyModel, ctx: Context| async move {
ctx.log("Hello, world!").await.unwrap();
Ok(EmptyModel)
});Sourcepub async fn put_stream(
&self,
data: impl Into<Vec<u8>>,
) -> Result<(), HatchetError>
pub async fn put_stream( &self, data: impl Into<Vec<u8>>, ) -> Result<(), HatchetError>
Send a stream event to the Hatchet API. Useful for streaming data such as LLM tokens or progress updates from a task to consumers.
ⓘ
use hatchet_sdk::{Hatchet, EmptyModel};
let hatchet = Hatchet::from_env().await.unwrap();
let task = hatchet.task("my-task", |_input: EmptyModel, ctx: Context| async move {
ctx.put_stream(b"chunk 1".to_vec()).await.unwrap();
ctx.put_stream(b"chunk 2".to_vec()).await.unwrap();
Ok(EmptyModel)
});Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl !UnwindSafe for Context
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request