Git Product home page Git Product logo

cain's Introduction

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.

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.

defmodule MyWorker do
  use Cain.ExternalWorker, [
    client: My.HTTPClient   # default: Cain.Client.Default
    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:

  • 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
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, 
    client: My.HTTPClient   #default: Cain.Client.Default
    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 modeled DMN table.

Installation

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

cain's People

Contributors

pfitz avatar timstawowski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

pfitz

cain's Issues

Redesign Rest-calls

Rest-calls should be invoked only if the process-instance representation confirms as a valid (camunda-rest-logic) request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.