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

External Task Client

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

defmodule MyWorker do
use Cain.ExternalWorker, [
max_tasks: 5, # default: 3
use_priority: true, # default: false
polling_interval: 1000 # default: 3000
]
end

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

def register_topics do
[{:my_topic, {MyTopicHandler, :handle_topic, [:my_arg], [lock_duration: 5000]}]
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

defmodule MyTopicHandler do
def handle_topic(payload, :my_arg) do
do_something_with_payload(payload)
case an_external_service_call() do
:ok ->
# provide a map with atom keys to response with variables
MyWorker.success()
{:error, error} ->
MyWorker.retry("external_service_error", inspect(error), 3, 3000)
_unexpected ->
MyWorker.create_incident("unexpected_error", "See the logs")
end
end
end

DMN Evaluation

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

defmodule MyDecisionTable do
use Cain.DecisionTable, definition_key: "MY_TABLE"
end

And evaluate.

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

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

Installation

def deps do
[
{:cain, "~> 0.3.0"}
]
end