Struct zeebe::JobWorkerBuilder
source · [−]pub struct JobWorkerBuilder { /* private fields */ }
Expand description
Configuration for an asynchronous worker process.
Implementations
sourceimpl JobWorkerBuilder
impl JobWorkerBuilder
sourcepub fn with_job_type<T: Into<String>>(self, job_type: T) -> Self
pub fn with_job_type<T: Into<String>>(self, job_type: T) -> Self
Set the job type of the worker.
sourcepub fn with_worker_name<T: Into<String>>(self, worker: T) -> Self
pub fn with_worker_name<T: Into<String>>(self, worker: T) -> Self
Set the worker name (mostly used for logging)
sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Set the worker job timeout.
See the requesting jobs docs for more details.
sourcepub fn with_request_timeout(self, request_timeout: Duration) -> Self
pub fn with_request_timeout(self, request_timeout: Duration) -> Self
Set the worker request timeout.
See the requesting jobs docs for more details.
sourcepub fn with_max_jobs_active(self, max_jobs_active: u32) -> Self
pub fn with_max_jobs_active(self, max_jobs_active: u32) -> Self
Set the maximum jobs to activate at a time by the worker.
sourcepub fn with_concurrency(self, concurrency: u32) -> Self
pub fn with_concurrency(self, concurrency: u32) -> Self
Set the max number of jobs to run concurrently.
sourcepub fn with_handler<T, R>(self, handler: T) -> Self where
T: Fn(Client, Job) -> R + 'static,
R: Future<Output = ()> + 'static,
pub fn with_handler<T, R>(self, handler: T) -> Self where
T: Fn(Client, Job) -> R + 'static,
R: Future<Output = ()> + 'static,
Set the handler function for the worker.
sourcepub fn with_auto_handler<F, T, R, O, E>(self, handler: F) -> Self where
F: HandlerFactory<T, R, O, E>,
T: FromJob,
R: Future<Output = Result<O, E>> + 'static,
O: Serialize,
E: Error,
pub fn with_auto_handler<F, T, R, O, E>(self, handler: F) -> Self where
F: HandlerFactory<T, R, O, E>,
T: FromJob,
R: Future<Output = Result<O, E>> + 'static,
O: Serialize,
E: Error,
Set a handler function that completes or fails the job based on the result rather than having to explicitly use the client to report job status.
Examples
use serde::{Deserialize, Serialize};
use thiserror::Error;
use zeebe::{Client, Data};
use futures::future;
let client = Client::new();
// Given an app-specific error
#[derive(Error, Debug)]
enum MyError {
#[error("unknown error occurred")]
Unknown,
}
// And app-specific job data
#[derive(Deserialize)]
struct MyJobData {
my_property: String,
my_other_property: String,
}
// And app-specific job result
#[derive(Serialize)]
struct MyJobResult {
result: u32,
}
// Async job handler function
async fn handle_job(client: Client, data: Data<MyJobData>) -> Result<MyJobResult, MyError> {
Ok(MyJobResult { result: 42 })
}
// Example use with async function
let job = client
.job_worker()
.with_job_type("my-job-type")
.with_auto_handler(handle_job)
.run()
.await?;
// Use with closure
let job = client
.job_worker()
.with_job_type("my-job-type")
.with_auto_handler(|client: Client, my_job_data: Data<MyJobData>| {
future::ok::<_, MyError>(MyJobResult { result: 42 })
})
.run()
.await?;
sourcepub fn with_state<T: 'static>(self, t: T) -> Self
pub fn with_state<T: 'static>(self, t: T) -> Self
Set state to be persisted across job auto handler
invocations.
Examples
use futures::future;
use serde::Serialize;
use std::cell::Cell;
use thiserror::Error;
use zeebe::{Client, State};
#[derive(Error, Debug)]
enum MyError {}
#[derive(Serialize)]
struct MyJobResult {
result: u32,
}
struct MyJobState {
total: Cell<u32>,
}
let client = Client::default();
let job_state = MyJobState {
total: Cell::new(0),
};
let _job = client
.job_worker()
.with_job_type("my-job-type")
.with_auto_handler(|my_job_state: State<MyJobState>| {
future::ok::<_, MyError>(MyJobResult { result: 42 })
})
.with_state(job_state)
.run()
.await?;
sourcepub fn with_fetch_variables(self, fetch_variables: Vec<String>) -> Self
pub fn with_fetch_variables(self, fetch_variables: Vec<String>) -> Self
Set the list of variables to fetch as the job variables.
By default all visible variables at the time of activation for the scope of the job will be returned.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for JobWorkerBuilder
impl !Send for JobWorkerBuilder
impl !Sync for JobWorkerBuilder
impl Unpin for JobWorkerBuilder
impl !UnwindSafe for JobWorkerBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message T
in a tonic::Request
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more