pub struct Worker<Q: QueueWorker, E: Executor> { /* private fields */ }Expand description
Connects a queue consumer to an executor, processing one task at a time.
Only NatsOpenaiWorker::from_env_or_default currently has a public
constructor (with nats-queue enabled). Other queue/executor combinations
require a caller-managed loop using their respective traits.
Implementations§
Source§impl Worker<NatsWorker, ExecutorAsyncOpenai>
impl Worker<NatsWorker, ExecutorAsyncOpenai>
Sourcepub async fn from_env_or_default() -> Result<Self>
pub async fn from_env_or_default() -> Result<Self>
Builds the NATS consumer and API executor from their environment settings.
Requires OPENAI_API_DEFAULT_MODEL and a reachable NATS server. See
NatsWorker::from_env_or_default and
ExecutorAsyncOpenai::from_env_or_default for defaults.
Source§impl<Q: QueueWorker, E: Executor> Worker<Q, E>
impl<Q: QueueWorker, E: Executor> Worker<Q, E>
Sourcepub async fn run(self) -> Result<()>
pub async fn run(self) -> Result<()>
Processes tasks sequentially until the queue returns None or an error.
Queue and executor errors stop the loop immediately; execution errors
are not converted into replies, and no application-level retry occurs.
Responses with success == false are sent normally and do not stop it.
A polling queue returning None ends the loop even if more work may arrive.
There is no shutdown signal; callers must arrange cancellation themselves.
Trait Implementations§
Source§impl<Q: QueueWorker, E: Executor> QueueWorker for Worker<Q, E>
impl<Q: QueueWorker, E: Executor> QueueWorker for Worker<Q, E>
Source§type Message = <Q as QueueWorker>::Message
type Message = <Q as QueueWorker>::Message
Source§async fn receive_task(&self) -> Result<Option<WrappedTask<Self::Message>>>
async fn receive_task(&self) -> Result<Option<WrappedTask<Self::Message>>>
None when none is available or the stream ends. Read more