Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .github_workflows/ci.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
otp: ["25.x", "26.x", "27.x"]
elixir: ["1.15.x", "1.16.x", "1.17.x"]
elixir: ["1.15.x", "1.16.x", "1.17.x", "1.18.x"]
req: ["0.5.7"]
# Exclude incompatible combinations of OTP and Elixir
exclude:
Expand All @@ -26,12 +26,6 @@ jobs:
- name: Check out Repository
uses: actions/checkout@v4

- name: Set up SSH Agent
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: |
${{ secrets.DEPLOY_KEY_SDK_INTERNAL_API_ELIXIR }}

- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Unreleased changes will be displayed here upon implementation.

## [2.0.0] - 2025-06-16

### Breaking Changes

- The BOX-ID internal actions `api` and `document_ai` have been moved to a separate repository.
Use the `http` action with the appropriate endpoint instead.

## [1.1.1] - 2025-05-22

### Fixed
Expand All @@ -31,6 +38,7 @@ Unreleased changes will be displayed here upon implementation.
- Support for Req 0.3.x (Note that, unrelated to the changes in this library, a warning will be
logged on every request if used together with Finch >= 0.17)

[unreleased]: https://github.com/box-id/workflow_engine/compare/1.1.1...HEAD
[unreleased]: https://github.com/box-id/workflow_engine/compare/2.0.0...HEAD
[2.0.0]: https://github.com/box-id/workflow_engine/releases/tag/2.0.0
[1.1.0]: https://github.com/box-id/workflow_engine/releases/tag/1.1.0
[1.1.1]: https://github.com/box-id/workflow_engine/releases/tag/1.1.1
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))

.PHONY: help test

test:
mix test

test-document-ai:
mix test test/actions/document_ai_test.exs --include external_service
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,71 @@ def deps do
end
```

## Extending Workflow Engine
To extend Workflow Engine with custom actions, implement the `WorkflowEngine.Action` behaviour.

This is a minimal example of a custom action that multiplies a value by a given factor and stores the result in the workflow state:
```elixir
defmodule MyApp.FooAction do
@behaviour WorkflowEngine.Action

@impl true
def execute(workflow_state, %{"type" => "multiply"} = step) do
# Implement your action logic here

multiply_by = get_required(step, "multiply_by")
source_key = get_required(step, "source_key")

value = Map.get(workflow_state, source_key, 1)

new_state =
Map.put(workflow_state, "multiply_result", value * multiply_by)

{:ok, {new_state, nil}}


rescue
# Wrap all error messages & add current state
e in WorkflowEngine.Error ->
reraise WorkflowEngine.Error,
[message: "FooAction: " <> e.message, state: state],
__STACKTRACE__
end

defp get_required(step, key) do
case Map.fetch(step, key) do
{:ok, value} when not is_nil(value) ->
value

_ ->
raise WorkflowEngine.Error,
message: "Missing required step parameter \"#{key}\"."
end
end
end
```

Then, setup the action in a customized module that implements the `WorkflowEngine`:

```elixir
defmodule MyAppNamespace.WorkflowEngine do
def evaluate(workflow, opts \\ []) do
state = %WorkflowEngine.State{
vars: Keyword.fetch!(opts, :vars),
actions: %{
"multiply" => MyApp.FooAction,
}
}
WorkflowEngine.evaluate(state, workflow)
end
end

### WorkflowEngine.State Attributes

- `vars`: A map of variables that can be used in the workflow.
- `json_logic_mod`: The module implementing the JSON Logic evaluation logic.
- `actions`: A map of action types to their respective modules. This allows you to define custom actions that can be used in workflows.

## Error Handling

Since workflows are dynamic (and potentially user-provided), Workflow Engine and its actions need
Expand Down
2 changes: 0 additions & 2 deletions config.env.skeleton

This file was deleted.

9 changes: 0 additions & 9 deletions config/runtime.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
import Config
import ConfigHelpers

if config_env() == :test do
config :bxdk, MQTT, enabled: false

config :workflow_engine, WorkflowEngine.Actions.DocumentAi,
api_key: get_env("WORKFLOW_DOCUMENT_AI_API_KEY", ""),
endpoint: get_env("WORKFLOW_DOCUMENT_AI_API_ENDPOINT", "")
end
3 changes: 1 addition & 2 deletions lib/actions/action.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
defmodule WorkflowEngine.Action do
@moduledoc """
Behavior that describes the necessary methods for an workflow action, as seen in
WorkflowEngine.Actions.Api.
Behavior that describes the necessary methods for an workflow action.
"""

alias WorkflowEngine.State
Expand Down
111 changes: 0 additions & 111 deletions lib/actions/api.ex

This file was deleted.

135 changes: 0 additions & 135 deletions lib/actions/document_ai.ex

This file was deleted.

Loading
Loading