pub struct Task {
pub id: u128,
pub task_type: TaskType,
pub contents: Value,
pub model: Option<String>,
pub max_tokens: Option<u64>,
pub payload: Option<Value>,
}Expand description
Serializable envelope for work submitted to a queue or executor.
Use TaskBuilder for chat tasks. Derived Default has ID zero and null
contents, so it is not an executable chat request.
Fields§
§id: u128Correlation ID; memory queues require uniqueness for outstanding tasks.
task_type: TaskTypeOperation encoded in Self::contents.
contents: ValueJSON input matching the task type; chat tasks contain a TaskChat.
model: Option<String>Explicit model, or None to use the producer/executor default.
max_tokens: Option<u64>Requested output limit; the API executor casts this to u32 unchecked.
payload: Option<Value>Opaque caller metadata preserved in the response task.
Implementations§
Source§impl Task
impl Task
Sourcepub async fn send_and_wait<Q: QueueProducer>(
self,
queue: &Q,
timeout_secs: Option<u64>,
) -> Result<Response>
pub async fn send_and_wait<Q: QueueProducer>( self, queue: &Q, timeout_secs: Option<u64>, ) -> Result<Response>
Submits this task and retrieves its response, which may be unsuccessful.
With std, Some(seconds) limits only the response wait after submission
and requires a Tokio runtime with time enabled. Expiry does not cancel
worker execution. None adds no timeout; backend polling semantics still
apply. Without std, a supplied timeout errors before sending.
Submission/retrieval failures, timeout expiry, and None responses return
errors. Check the response’s success field separately from the Result.
Source§impl Task
impl Task
Sourcepub fn with_id(self, id: u128) -> Self
pub fn with_id(self, id: u128) -> Self
Replaces the correlation ID; avoid duplicates among outstanding tasks.
Sourcepub fn with_max_tokens(self, max_tokens: u64) -> Self
pub fn with_max_tokens(self, max_tokens: u64) -> Self
Sets the output limit; the API executor casts it to u32 unchecked.
Sourcepub fn with_payload<P: Serialize>(self, payload: P) -> Self
pub fn with_payload<P: Serialize>(self, payload: P) -> Self
Attaches opaque caller metadata to be returned with the task.
§Panics
Panics if the payload cannot be serialized as JSON.
Sourcepub fn with_model<M: ToString>(self, model: M) -> Self
pub fn with_model<M: ToString>(self, model: M) -> Self
Overrides the model used for NATS routing and API execution.
Sourcepub fn try_to_chat(&self) -> Result<TaskChat>
pub fn try_to_chat(&self) -> Result<TaskChat>
Decodes contents as TaskChat, returning an error for incompatible JSON.
Does not inspect Self::task_type or validate schema/model settings.