A workflow engine provides an application with the following features:
- providing visibility of the state of your application
- auditing business processes
- orchestration within an application.
When your application requires one or more of these features this library might be a solution for you.
If available in Hex, the package can be installed
by adding we
to your list of dependencies in mix.exs
:
def deps do
[
{:we, "~> 0.1.0"}
]
end
Start the application in your mix.exs file of your project.
def application do
[
extra_applications: [:logger],
mod: {WE.Application, [storage_adapters: []]}
]
end
The WE
module functions as an api. Except for constructing a workflow, all the interactions with this library are done through this module.
The WE.Workflow
module is used to define workflows.
example:
Workflow.workflow("message event workflow")
|> Workflow.add_start_event("start")
|> Workflow.add_message_event("receive message")
|> Workflow.add_end_event("stop")
|> Workflow.add_default_sequence_flow("start", "receive message")
|> Workflow.add_default_sequence_flow("message", "stop")
For more examples take a look at WE.TestWorkflowHelpers
.
The WE.Engine
module is the heart of this library. It can be contrilled form the WE
api module.
There are two steps that need to be taken before a workflow is running. The engine needs to be initialised and after
this is one it needs to be started.
{:ok, engine_pid} = init_engine("your business_id", my_workflow)
"your business_id"
|> start_engine("your business_id")
During initialization the workflow is validated. Take a look at WE.Workflow.Validator
to see which validations are done.
The workflow engine is updated through the api.
def start_doing_something(args)
...
WE.start_task("your business id", "task_name")
... do the task
end
def complete doing something(args)
WE.complete_task("your business id", "task_name")
end
After a step in the workflow is done there are two ways to go to the next step. The first one is just follow the outgoing
default sequence flow. But there is also the possibility to follow one or more non default flows. This is done by adding
a list of names of the next steps to the WE.complete_task
or WE.handle_event/3
Each workflow or each step (except start and end events) within a workflow can have a document attached to it. A document is a piece of business data that is needed to make decisions within the workflow. Documents are defined on a workflow and the engine will check if a required document is added before it will move on to a next state.
!A word of caution. Do not use these documents to store large binaries or enormous maps. It is intended for a small collection of workflow relevant data. If you need to work with big data items it is recommended to store it seperately in a database and use a unique reference id and optionally some meta data on the data item.
In development an in memory storage adapter is loaded. For production it is advisable to pass a storage adapter that
provides storage to your storage solution (example: Postgresql). A storage asapter needs to implement the WE.StorageAdapter
behaviour.
def application do
[
extra_applications: [:logger],
mod: {WE.Application, [storage_adapters: [YourApp.YourStorageAdapter]]}
]
end
- Integrate Telemetry
- Create a web visualisation library
Any contribution is appreciated however some contributions are more appreciated than others. From the most to least appreciated types of contribution: