pub struct JobWorkerBuilder { /* private fields */ }
Expand description

Configuration for an asynchronous worker process.

Implementations

Create a new job worker builder.

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.

Start the worker as a future. To stop the worker, simply drop the future.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

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

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

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

Calls U::from(self).

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

Wrap the input message T in a tonic::Request

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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