项目作者: timstawowski

项目描述 :
Camunda-BPM REST-Intepreter
高级语言: Elixir
项目地址: git://github.com/timstawowski/cain.git
创建时间: 2019-10-24T05:24:54Z
项目社区:https://github.com/timstawowski/cain

开源协议:Apache License 2.0

下载


Cain

Camunda-REST-API-Interpreter to handle common Camunda specific workflow use cases for a more clearly usage by hiding the REST-Calls under the hood.

Covered

  • Handle external tasks
  • Invoke DMN evaluations

HTTP-Client

Cain.ExternalWorker and Cain.DecisionTable are using Cain.Client.Default for submitting HTTP requests on default.
Therefore it’s using the Tesla library. If you want to add you own HTTP-Client it has to implement the Cain.Client behaviour and also has to support handling of JSON data.

Using Cain.Client.Default requires to add following configuration in your config.

  1. config :cain, Cain.Endpoint, url: "http://localhost:4004/engine-rest/"

External Task Client

Use Cain.ExternalWorker for referencing your external task function implementation in your application.

  1. defmodule MyWorker do
  2. use Cain.ExternalWorker, [
  3. client: My.HTTPClient # default: Cain.Client.Default
  4. max_tasks: 5, # default: 3
  5. use_priority: true, # default: false
  6. polling_interval: 1000 # default: 3000
  7. ]
  8. end

Add register_topics/1 and create a list of a tuple with the following elements:

  • Name of the topic that has been given in the BPMN-Process-Model
  • Function implementation with a tuple of Module, function and args the topic refers to
  • Setting lock duration in milliseconds, defaults to 3000ms
  1. def register_topics do
  2. [{:my_topic, {MyTopicHandler, :handle_topic, [:my_arg]}, [lock_duration: 5000]}]
  3. end

Response in the referenced function by using the provided API in MyWorker.

Notice: The payload of a topic fetch is always provided as the first argument and needs to be considered on your function implementation

  1. defmodule MyTopicHandler do
  2. def handle_topic(payload, :my_arg) do
  3. do_something_with_payload(payload)
  4. case an_external_service_call() do
  5. :ok ->
  6. # provide a map with atom keys to response with variables
  7. MyWorker.success()
  8. {:error, error} ->
  9. MyWorker.retry("external_service_error", inspect(error), 3, 3000)
  10. _unexpected ->
  11. MyWorker.create_incident("unexpected_error", "See the logs")
  12. end
  13. end
  14. end

DMN Evaluation

Use Cain.DecisionTable and set the corresponding definition_key of the deployed table in the engine.

  1. defmodule MyDecisionTable do
  2. use Cain.DecisionTable,
  3. client: My.HTTPClient #default: Cain.Client.Default
  4. definition_key: "MY_TABLE"
  5. end

And evaluate.

  1. MyDecisionTable.evaluate(%{first: 1, second: "Second"})
  2. # {:ok, [%{is_valid: true}]}

The return value depends on the output definition of the modeled DMN table.

Installation

  1. def deps do
  2. [
  3. {:cain, "~> 0.3.0"}
  4. ]
  5. end