4 releases

0.4.0 May 21, 2024
0.3.2 Feb 21, 2024
0.3.1 Feb 20, 2024
0.3.0 Feb 20, 2024

#2 in #acts

MIT license

51KB
1K SLoC

acts-channel

Build

provides an acts client channel for workflow engine server acts-server

The crate is called acts-channel and you can depend on it via cargo:

[dependencies]
acts-channel = "*"

If you want to use the git version:

[dependencies]
acts-channel = { git = "https://github.com/yaojianpin/acts-channel.git" }

Usage

Before connecting, please download acts-server and start it

Message

Listening to the message from acts-server

use acts_channel::{ActsChannel, ActsOptions};

fn on_message(msg: &Message) {
    // do something
}
let uri = format!("http://{hostname}:{port}");
let client = ActsChannel::new(
    &uri,
    "my_client_id",

    // the ActsOptions can set to filter the messages with type, event, tag and key
    ActsOptions {
        on_message: Some(on_message),
        ..ActsOptions::default()
    },
)
.await

Action

Executes action to interact with acts-server, such as deploy, start, push, remove, submit, complete, back, cancel, skip, error, etc. For more information, please see acts-server

Deploy

let resp = client
    .deploy("mid", "model yml here").await?;
let result: ActionResult = resp.into_inner();

Start

let mut vars = Vars::new();
vars.insert("var1", &true.into());
let resp = client
    .submit("pid", "tid", &vars).await?;
let result: ActionResult = resp.into_inner();

Complete

let mut vars = Vars::new();
vars.insert("var1", json!("value1"));
let resp = client
    .complete("pid", "tid", &vars).await?;
let result: ActionResult = resp.into_inner();

Back

let mut vars = Vars::new();
vars.insert("to", &json!("step1"));
let resp = client
    .back("pid", "tid", &vars).await?;
let result: ActionResult = resp.into_inner();

Cancel

let mut vars = Vars::new();
vars.insert("var1", json!("value1"));
let resp = client
    .cancel("pid", "tid", &vars).await?;
let result: ActionResult = resp.into_inner();

Skip

let mut vars = Vars::new();
vars.insert("var1", json!("value1"));
let resp = client
    .skip("pid", "tid", &vars).await?;
let result: ActionResult = resp.into_inner();

Error

let mut vars = Vars::new();
vars.insert("error_code", json!("err1"));
let resp = client
    .error("pid", "tid", &vars).await?;
let result: ActionResult = resp.into_inner();

Push

let mut vars = Vars::new();
vars.insert("var1", json!("value1"));
let resp = client
    .push("pid", "tid", &vars).await?;
let result: ActionResult = resp.into_inner();

Remove

let mut vars = Vars::new();
vars.insert("var1", json!("value1"));
let resp = client
    .remove("pid", "tid", &vars).await?;
let result: ActionResult = resp.into_inner();

Dependencies

~8–15MB
~185K SLoC