pub struct WorkerBuilder<Job, Source, Middleware> { /* private fields */ }
Expand description

An abstract that allows building a Worker. Usually the output is ReadyWorker but you can implement your own via WorkerFactory

Implementations§

source§

impl WorkerBuilder<(), (), Identity>

source

pub fn new<T: AsRef<str>>(name: T) -> WorkerBuilder<(), (), Identity>

Build a new WorkerBuilder instance with a name for the worker to build

source§

impl<J, S, M> WorkerBuilder<J, S, M>

source

pub fn stream<NS: Stream<Item = Result<Option<JobRequest<NJ>>, E>>, E, NJ>( self, stream: NS ) -> WorkerBuilder<NJ, NS, M>

Consume a stream directly

source

pub fn with_stream<NS: Fn(&WorkerId) -> ST, NJ, E, ST: Stream<Item = Result<Option<JobRequest<NJ>>, E>>>( self, stream: NS ) -> WorkerBuilder<NJ, ST, M>

Get the WorkerId and build a stream. Useful when you want to know what worker is consuming the stream.

source§

impl<Job, Stream, Serv> WorkerBuilder<Job, Stream, Serv>

source

pub fn middleware<NewService>( self, f: impl Fn(ServiceBuilder<Serv>) -> ServiceBuilder<NewService> ) -> WorkerBuilder<Job, Stream, NewService>

Allows of decorating the service that consumes jobs. Allows adding multiple tower middleware

source

pub fn layer<U>(self, layer: U) -> WorkerBuilder<Job, Stream, Stack<U, Serv>>where Serv: Layer<U>,

Shorthand for decoration. Allows adding a single layer tower middleware

Trait Implementations§

source§

impl<Job, Source, Middleware> Debug for WorkerBuilder<Job, Source, Middleware>

source§

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

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

impl<J: 'static, M, Mq> WithMq<Stack<Extension<Mq>, Stack<AckLayer<Mq, J>, M>>, Mq> for WorkerBuilder<(), (), M>where Mq: MessageQueue<J> + Send + Sync + 'static + Clone + Ack<J>, M: Send + Sync + 'static,

Available on crate feature mq only.
§

type Job = J

The job to consume
§

type Stream = Pin<Box<dyn Stream<Item = Result<Option<JobRequest<J>>, JobStreamError>> + Send>>

The MessageQueue to produce jobs
source§

fn with_mq( self, mq: Mq ) -> WorkerBuilder<J, Self::Stream, Stack<Extension<Mq>, Stack<AckLayer<Mq, J>, M>>>

The builder method to produce a default WorkerBuilder that will consume jobs
source§

impl<J: 'static + Send + Sync, M, ST> WithStorage<Stack<Extension<ST>, Stack<AckLayer<ST, J>, M>>, ST> for WorkerBuilder<(), (), M>where ST: Storage<Output = J> + Send + Sync + 'static, M: Send + Sync + 'static,

Available on crate feature storage only.
§

type Job = J

The job to consume
§

type Stream = Pin<Box<dyn Stream<Item = Result<Option<JobRequest<J>>, JobStreamError>> + Send>>

The source of jobs
source§

fn with_storage_config( self, storage: ST, config: impl Fn(WorkerConfig) -> WorkerConfig ) -> WorkerBuilder<J, Self::Stream, Stack<Extension<ST>, Stack<AckLayer<ST, J>, M>>>

The builder method to produce a configured WorkerBuilder that will consume jobs
source§

fn with_storage(self, storage: ST) -> WorkerBuilder<Self::Job, Self::Stream, NS>

The builder method to produce a default WorkerBuilder that will consume jobs
source§

impl<J, S, M, Ser, E, Request> WorkerFactory<J, Ser> for WorkerBuilder<J, S, M>where S: Stream<Item = Result<Option<Request>, E>> + Send + 'static + Unpin, J: Job + Send + 'static, M: Layer<Ser>, <M as Layer<Ser>>::Service: Service<Request> + Send + 'static, E: Sync + Send + 'static + Error, Request: Send + HasJobContext, <<M as Layer<Ser>>::Service as Service<Request>>::Future: Send + 'static, Ser: Service<Request>, <Ser as Service<Request>>::Error: Debug, <<M as Layer<Ser>>::Service as Service<Request>>::Error: Debug,

source§

fn build(self, service: Ser) -> ReadyWorker<S, <M as Layer<Ser>>::Service>

Convert a worker builder to a worker ready to consume jobs

§

type Worker = ReadyWorker<S, <M as Layer<Ser>>::Service>

The worker to build

Auto Trait Implementations§

§

impl<Job, Source, Middleware> !RefUnwindSafe for WorkerBuilder<Job, Source, Middleware>

§

impl<Job, Source, Middleware> Send for WorkerBuilder<Job, Source, Middleware>where Job: Send, Middleware: Send, Source: Send,

§

impl<Job, Source, Middleware> !Sync for WorkerBuilder<Job, Source, Middleware>

§

impl<Job, Source, Middleware> Unpin for WorkerBuilder<Job, Source, Middleware>where Job: Unpin, Middleware: Unpin, Source: Unpin,

§

impl<Job, Source, Middleware> !UnwindSafe for WorkerBuilder<Job, Source, Middleware>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
§

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

§

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
source§

impl<J, W, F> WorkerFactoryFn<J, F> for Wwhere W: WorkerFactory<J, JobFn<F>>,

§

type Worker = <W as WorkerFactory<J, JobFn<F>>>::Worker

The worker build
source§

fn build_fn(self, f: F) -> <W as WorkerFactoryFn<J, F>>::Worker

Builds a WorkerFactoryFn using a crate::job_fn::JobFn service that can be used to generate new Worker actors using the build method Read more