1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//! A rust client for defining, orchestrating, and monitoring business processes
//! across microservices using [Zeebe].
//!
//! ## What is Zeebe?
//!
//! [Zeebe] is a workflow engine for microservices orchestration. Zeebe ensures
//! that, once started, flows are always carried out fully, retrying steps in
//! case of failures. Along the way, Zeebe maintains a complete audit log so
//! that the progress of flows can be monitored. Zeebe is fault tolerant and
//! scales seamlessly to handle growing transaction volumes.
//!
//! [Zeebe]: https://zeebe.io
//!
//! ## Example
//!
//! ```no_run
//! use serde_json::json;
//! use zeebe::{Client, Job};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     // Create a zeebe client
//!     let client = Client::default();
//!
//!     // Deploy a workflow
//!     client
//!         .deploy_workflow()
//!         .with_resource_file("examples/workflows/order-process.bpmn")
//!         .send()
//!         .await?;
//!
//!     // Create a new workflow instance
//!     client
//!         .create_workflow_instance()
//!         .with_bpmn_process_id("order-process")
//!         .with_latest_version()
//!         .with_variables(json!({"orderId": 31243}))
//!         .send()
//!         .await?;
//!
//!     // Process a job type within the workflow
//!     client
//!         .job_worker()
//!         .with_job_type("payment-service")
//!         .with_handler(handle_job)
//!         .run()
//!         .await?;
//!
//!     Ok(())
//! }
//!
//! async fn handle_job(client: Client, job: Job) {
//!     /// your job processing logic...
//!
//!     let _ = client.complete_job().with_job_key(job.key()).send().await;
//! }
//! ```
//!
//! Or with job success and failure reported for you automatically from your
//! function result:
//!
//! ```no_run
//! use serde::{Deserialize, Serialize};
//! use thiserror::Error;
//! use zeebe::Client;
//! use futures::future;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! 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: MyJobData) -> Result<MyJobResult, MyError> {
//!    Ok(MyJobResult { result: 42 })
//! }
//!
//! // You can run a worker from your function with results auto reported
//! let job = client
//!     .job_worker()
//!     .with_job_type("my-job-type")
//!     .with_auto_handler(handle_job)
//!     .run()
//!     .await?;
//!
//! // OR you can run a closure and have the results auto reported
//! let job = client
//!     .job_worker()
//!     .with_job_type("my-job-type")
//!     .with_auto_handler(|client: Client, my_job_data: MyJobData| {
//!         future::ok::<_, MyError>(MyJobResult { result: 42 })
//!     })
//!     .run()
//!     .await?;
//!
//! # Ok(())
//! # }
//! ```
#![warn(
    missing_debug_implementations,
    missing_docs,
    rust_2018_idioms,
    bad_style,
    const_err,
    dead_code,
    improper_ctypes,
    non_shorthand_field_patterns,
    no_mangle_generic_items,
    overflowing_literals,
    path_statements,
    patterns_in_fns_without_body,
    private_in_public,
    unconditional_recursion,
    unused,
    unused_allocation,
    unused_comparisons,
    unused_parens,
    while_true
)]

pub(crate) mod client;
pub(crate) mod error;
pub(crate) mod job;
pub(crate) mod topology;
pub(crate) mod util;
pub(crate) mod worker;
pub(crate) mod workflow;

#[allow(clippy::all)]
pub(crate) mod proto {
    tonic::include_proto!("gateway_protocol");
}

pub use client::{Client, ClientConfig};
pub use error::{Error, Result};
pub use job::{
    CompleteJobBuilder, CompleteJobResponse, FailJobBuilder, FailJobResponse, Job,
    ThrowErrorBuilder, ThrowErrorResponse, UpdateJobRetriesBuilder, UpdateJobRetriesResponse,
};
pub use topology::{BrokerInfo, Partition, TopologyBuilder, TopologyResponse};
pub use util::{
    PublishMessageBuilder, PublishMessageResponse, ResolveIncidentBuilder, ResolveIncidentResponse,
};
pub use worker::JobWorkerBuilder;
pub use workflow::{
    CancelWorkflowInstanceBuilder, CancelWorkflowInstanceResponse, CreateWorkflowInstanceBuilder,
    CreateWorkflowInstanceResponse, CreateWorkflowInstanceWithResultBuilder,
    CreateWorkflowInstanceWithResultResponse, DeployWorkflowBuilder, DeployWorkflowResponse,
    SetVariablesBuilder, SetVariablesResponse, WorkflowMetadata, WorkflowResourceType,
};