Struct zeebe::JobWorkerBuilder [−][src]
pub struct JobWorkerBuilder { /* fields omitted */ }
Expand description
Configuration for an asynchronous worker process.
Implementations
Set the job type of the worker.
Set the worker name (mostly used for logging)
Set the worker job timeout.
See the requesting jobs docs for more details.
Set the worker request timeout.
See the requesting jobs docs for more details.
Set the maximum jobs to activate at a time by the worker.
Set the max number of jobs to run concurrently.
Set the handler function for the worker.
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?;
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?;
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
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Wrap the input message T
in a tonic::Request
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more