Skip to content

Commit 3fd81a8

Browse files
authored
removed box-id specific actions and moved it into repo box-id/workflow_engine_actions (#9)
PD-3318 * removed box-id specific actions and moved it into repo box-id/workflow_engine_actions * added 1.18.x to ci tests * bump major version 2.0.0
1 parent 1621d87 commit 3fd81a8

File tree

16 files changed

+86
-507
lines changed

16 files changed

+86
-507
lines changed
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
strategy:
88
matrix:
99
otp: ["25.x", "26.x", "27.x"]
10-
elixir: ["1.15.x", "1.16.x", "1.17.x"]
10+
elixir: ["1.15.x", "1.16.x", "1.17.x", "1.18.x"]
1111
req: ["0.5.7"]
1212
# Exclude incompatible combinations of OTP and Elixir
1313
exclude:
@@ -26,12 +26,6 @@ jobs:
2626
- name: Check out Repository
2727
uses: actions/checkout@v4
2828

29-
- name: Set up SSH Agent
30-
uses: webfactory/ssh-agent@v0.9.0
31-
with:
32-
ssh-private-key: |
33-
${{ secrets.DEPLOY_KEY_SDK_INTERNAL_API_ELIXIR }}
34-
3529
- name: Set up Elixir
3630
uses: erlef/setup-beam@v1
3731
with:

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
Unreleased changes will be displayed here upon implementation.
1111

12+
## [2.0.0] - 2025-06-16
13+
14+
### Breaking Changes
15+
16+
- The BOX-ID internal actions `api` and `document_ai` have been moved to a separate repository.
17+
Use the `http` action with the appropriate endpoint instead.
18+
1219
## [1.1.1] - 2025-05-22
1320

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

34-
[unreleased]: https://github.com/box-id/workflow_engine/compare/1.1.1...HEAD
41+
[unreleased]: https://github.com/box-id/workflow_engine/compare/2.0.0...HEAD
42+
[2.0.0]: https://github.com/box-id/workflow_engine/releases/tag/2.0.0
3543
[1.1.0]: https://github.com/box-id/workflow_engine/releases/tag/1.1.0
3644
[1.1.1]: https://github.com/box-id/workflow_engine/releases/tag/1.1.1

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ cnf ?= config.env
44
include $(cnf)
55
export $(shell sed 's/=.*//' $(cnf))
66

7+
.PHONY: help test
8+
79
test:
810
mix test
9-
10-
test-document-ai:
11-
mix test test/actions/document_ai_test.exs --include external_service

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,71 @@ def deps do
2727
end
2828
```
2929

30+
## Extending Workflow Engine
31+
To extend Workflow Engine with custom actions, implement the `WorkflowEngine.Action` behaviour.
32+
33+
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:
34+
```elixir
35+
defmodule MyApp.FooAction do
36+
@behaviour WorkflowEngine.Action
37+
38+
@impl true
39+
def execute(workflow_state, %{"type" => "multiply"} = step) do
40+
# Implement your action logic here
41+
42+
multiply_by = get_required(step, "multiply_by")
43+
source_key = get_required(step, "source_key")
44+
45+
value = Map.get(workflow_state, source_key, 1)
46+
47+
new_state =
48+
Map.put(workflow_state, "multiply_result", value * multiply_by)
49+
50+
{:ok, {new_state, nil}}
51+
52+
53+
rescue
54+
# Wrap all error messages & add current state
55+
e in WorkflowEngine.Error ->
56+
reraise WorkflowEngine.Error,
57+
[message: "FooAction: " <> e.message, state: state],
58+
__STACKTRACE__
59+
end
60+
61+
defp get_required(step, key) do
62+
case Map.fetch(step, key) do
63+
{:ok, value} when not is_nil(value) ->
64+
value
65+
66+
_ ->
67+
raise WorkflowEngine.Error,
68+
message: "Missing required step parameter \"#{key}\"."
69+
end
70+
end
71+
end
72+
```
73+
74+
Then, setup the action in a customized module that implements the `WorkflowEngine`:
75+
76+
```elixir
77+
defmodule MyAppNamespace.WorkflowEngine do
78+
def evaluate(workflow, opts \\ []) do
79+
state = %WorkflowEngine.State{
80+
vars: Keyword.fetch!(opts, :vars),
81+
actions: %{
82+
"multiply" => MyApp.FooAction,
83+
}
84+
}
85+
WorkflowEngine.evaluate(state, workflow)
86+
end
87+
end
88+
89+
### WorkflowEngine.State Attributes
90+
91+
- `vars`: A map of variables that can be used in the workflow.
92+
- `json_logic_mod`: The module implementing the JSON Logic evaluation logic.
93+
- `actions`: A map of action types to their respective modules. This allows you to define custom actions that can be used in workflows.
94+
3095
## Error Handling
3196

3297
Since workflows are dynamic (and potentially user-provided), Workflow Engine and its actions need

config.env.skeleton

Lines changed: 0 additions & 2 deletions
This file was deleted.

config/runtime.exs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
11
import Config
2-
import ConfigHelpers
3-
4-
if config_env() == :test do
5-
config :bxdk, MQTT, enabled: false
6-
7-
config :workflow_engine, WorkflowEngine.Actions.DocumentAi,
8-
api_key: get_env("WORKFLOW_DOCUMENT_AI_API_KEY", ""),
9-
endpoint: get_env("WORKFLOW_DOCUMENT_AI_API_ENDPOINT", "")
10-
end

lib/actions/action.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
defmodule WorkflowEngine.Action do
22
@moduledoc """
3-
Behavior that describes the necessary methods for an workflow action, as seen in
4-
WorkflowEngine.Actions.Api.
3+
Behavior that describes the necessary methods for an workflow action.
54
"""
65

76
alias WorkflowEngine.State

lib/actions/api.ex

Lines changed: 0 additions & 111 deletions
This file was deleted.

lib/actions/document_ai.ex

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)