Skip to main content

Worker

Struct Worker 

Source
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>

Source

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>

Source

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: Clone + QueueWorker, E: Clone + Executor> Clone for Worker<Q, E>

Source§

fn clone(&self) -> Worker<Q, E>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Q: Debug + QueueWorker, E: Debug + Executor> Debug for Worker<Q, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Q: QueueWorker, E: Executor> Executor for Worker<Q, E>

Source§

fn default_model(&self) -> &Arc<Option<String>>

Returns the fallback model used when a task does not specify one.
Source§

async fn execute(&self, task: Task) -> Result<Response>

Executes one task; Err indicates execution failed before a response.
Source§

impl<Q: QueueWorker, E: Executor> QueueWorker for Worker<Q, E>

Source§

type Message = <Q as QueueWorker>::Message

Backend-specific reply metadata attached to each received task.
Source§

async fn receive_task(&self) -> Result<Option<WrappedTask<Self::Message>>>

Receives a task, or None when none is available or the stream ends. Read more
Source§

async fn send_response( &self, message: Self::Message, response: Response, ) -> Result<()>

Sends a response using the metadata from the corresponding task.

Auto Trait Implementations§

§

impl<Q, E> Freeze for Worker<Q, E>
where Q: Freeze, E: Freeze,

§

impl<Q, E> RefUnwindSafe for Worker<Q, E>

§

impl<Q, E> Send for Worker<Q, E>
where Q: Send, E: Send,

§

impl<Q, E> Sync for Worker<Q, E>
where Q: Sync, E: Sync,

§

impl<Q, E> Unpin for Worker<Q, E>
where Q: Unpin, E: Unpin,

§

impl<Q, E> UnsafeUnpin for Worker<Q, E>
where Q: UnsafeUnpin, E: UnsafeUnpin,

§

impl<Q, E> UnwindSafe for Worker<Q, E>
where Q: UnwindSafe, E: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more