custom_auto_handler/
custom_auto_handler.rs1use std::{ops::Deref, time::Duration};
2use thiserror::Error;
3use zeebe_rs::{ActivatedJob, Client, WorkerOutputHandler};
4
5#[derive(Debug, Error)]
7pub enum MyErrorType {
8 #[error("")]
9 Fail,
10}
11
12struct MyResult<T>(pub Result<T, MyErrorType>);
15impl<T> Deref for MyResult<T> {
16 type Target = Result<T, MyErrorType>;
17
18 fn deref(&self) -> &Self::Target {
19 &self.0
20 }
21}
22
23impl<T> WorkerOutputHandler for MyResult<T>
25where
26 T: Send + 'static,
27{
28 async fn handle_result(self, client: Client, job: ActivatedJob) {
29 match *self {
30 Ok(_) => unreachable!("This will always fail!"),
31 Err(_) => {
32 let _ = client.fail_job().with_job_key(job.key()).send().await;
33 }
34 }
35 }
36}
37
38async fn always_fail(_client: Client, _job: ActivatedJob) -> MyResult<()> {
39 MyResult(Err(MyErrorType::Fail))
40}
41
42#[tokio::main]
43async fn main() -> Result<(), Box<dyn std::error::Error>> {
44 unsafe { std::env::set_var("RUST_BACKTRACE", "1") };
45
46 let client = Client::builder()
49 .with_address("http://localhost", 26500)
50 .with_oauth(
51 String::from("zeebe"),
52 String::from("zecret"),
53 String::from(
54 "http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token",
55 ),
56 String::from("zeebe-api"),
57 Duration::from_secs(30),
58 None,
59 )
60 .build()
61 .await?;
62
63 client.auth_initialized().await;
65
66 let worker = client
67 .worker()
68 .with_request_timeout(Duration::from_secs(1))
69 .with_job_timeout(Duration::from_secs(1))
70 .with_max_jobs_to_activate(1)
71 .with_concurrency_limit(1)
72 .with_job_type(String::from("placeholder"))
73 .with_handler(always_fail)
74 .build();
75
76 tokio::join!(worker.run());
77
78 Ok(())
79}