pub trait TaskBroker: Send + Sync {
// Required methods
fn submit(
&self,
task: AgentTask,
) -> impl Future<Output = Result<String>> + Send;
fn status(
&self,
task_id: &str,
) -> impl Future<Output = Result<TaskStatus>> + Send;
fn receive(&self) -> impl Future<Output = Result<Option<AgentTask>>> + Send;
fn complete(
&self,
task_id: &str,
result: TaskResult,
) -> impl Future<Output = Result<()>> + Send;
fn fail(
&self,
task_id: &str,
error: String,
) -> impl Future<Output = Result<()>> + Send;
// Provided method
fn none_means_closed(&self) -> bool { ... }
}Expand description
Trait for distributing agent tasks across workers.
Implement this for your message broker (AWS SQS, Google Pub/Sub, Azure Service Bus, Redis, NATS, RabbitMQ, etc.) to enable multi-process agent execution.
Required Methods§
Sourcefn submit(&self, task: AgentTask) -> impl Future<Output = Result<String>> + Send
fn submit(&self, task: AgentTask) -> impl Future<Output = Result<String>> + Send
Submits a task for execution. Returns the task ID.
Sourcefn status(
&self,
task_id: &str,
) -> impl Future<Output = Result<TaskStatus>> + Send
fn status( &self, task_id: &str, ) -> impl Future<Output = Result<TaskStatus>> + Send
Queries the current status of a task.
Sourcefn receive(&self) -> impl Future<Output = Result<Option<AgentTask>>> + Send
fn receive(&self) -> impl Future<Output = Result<Option<AgentTask>>> + Send
Waits for a task and returns it.
Returns Ok(None) when no task was obtained. What that means depends
on none_means_closed:
none_means_closed() == true— the broker is permanently closed and no further tasks will ever arrive; callers should stop polling.none_means_closed() == false(the default) — the queue was merely idle for one poll interval (e.g. a blocking-pop timeout or an empty fetch); callers should keep polling.
Provided Methods§
Sourcefn none_means_closed(&self) -> bool
fn none_means_closed(&self) -> bool
Whether receive returning Ok(None) means the
broker is permanently closed rather than momentarily idle.
Network brokers (Redis, NATS, SQS, Pub/Sub, Service Bus, …) poll with
a timeout and legitimately come up empty when the queue is idle, so the
default is false: an empty receive is a transient condition and the
caller should retry. Brokers with a real end-of-stream signal (e.g. an
in-process channel whose senders are gone, or a cancelled AMQP
consumer) override this to true so workers can shut down promptly.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".