Crates.io | snurr |
lib.rs | snurr |
version | 0.7.0 |
source | src |
created_at | 2024-09-01 18:41:53.507618 |
updated_at | 2024-11-06 13:25:06.795054 |
description | Read BPMN 2.0 files and run the process flow |
homepage | |
repository | https://github.com/sajox/snurr |
max_upload_size | |
id | 1359813 |
size | 93,503 |
Snurr can run the process flow from a Business Process Model and Notation (BPMN) 2.0 file created by https://demo.bpmn.io/new.
Read the Snurr documentation and explore the tests folder for more examples.
NOTE: To view or edit BPMN files in your project you can use the BPMN Editor plugin in VS Code.
BPMN diagram used in example.
[dependencies]
snurr = "0.7"
log = "0.4"
pretty_env_logger = "0.5"
use snurr::{Eventhandler, Process};
extern crate pretty_env_logger;
#[derive(Debug, Default)]
struct Counter {
count: u32,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
pretty_env_logger::init();
let bpmn = Process::new("example.bpmn")?;
let mut handler: Eventhandler<Counter> = Eventhandler::default();
handler.add_task("Count 1", |input| {
input.lock().unwrap().count += 1;
None
});
handler.add_gateway("equal to 3", |input| {
let result = if input.lock().unwrap().count == 3 {
"YES"
} else {
"NO"
};
result.into()
});
let pr = bpmn.run(&handler, Counter::default())?;
println!("Result: {:?}", pr.result);
Ok(())
}
If RUST_LOG=info is set when running example
INFO snurr::process::engine > Start: Begin process
INFO snurr::process::engine > SequenceFlow: count
INFO snurr::process::engine > Task: Count 1
INFO snurr::process::engine > SequenceFlow: control
INFO snurr::process::engine > Exclusive: equal to 3
INFO snurr::process::engine > SequenceFlow: NO
INFO snurr::process::engine > Task: Count 1
INFO snurr::process::engine > SequenceFlow: control
INFO snurr::process::engine > Exclusive: equal to 3
INFO snurr::process::engine > SequenceFlow: NO
INFO snurr::process::engine > Task: Count 1
INFO snurr::process::engine > SequenceFlow: control
INFO snurr::process::engine > Exclusive: equal to 3
INFO snurr::process::engine > SequenceFlow: YES
INFO snurr::process::engine > End: End process
Result: Counter { count: 3 }
Run or copy the simple.rs in the examples folder
RUST_LOG=info cargo run --example simple