Skip to content

Commit

Permalink
Merge branch 'master' of github.com:synrc/bpe
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Oct 10, 2022
2 parents ca9aa22 + 846b10e commit fbf3b31
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
6 changes: 4 additions & 2 deletions include/bpe.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@
received = [] :: [] | #ts{},
started = [] :: [] | #ts{},
executed = [] :: [] | #ts{},
status = [] :: [] | #status{} }).
status = [] :: [] | #status{},
routing = [] :: [] | list(),
permanent = false :: false | boolean() }).

-record(hist, { id = [] :: [] | #step{},
prev = [] :: [] | integer(),
Expand Down Expand Up @@ -152,7 +154,7 @@
userStarted = [] :: term(),
userModified = [] :: term(),
userFinished = [] :: term(),
params = [] :: term(),
root = [] :: term(),
filters = [] :: term(),
etc = [] :: term(),
flags = [] :: term(),
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule BPE.Mixfile do
def project do
[
app: :bpe,
version: "7.6.4",
version: "7.10.1",
description: "BPE Business Process Engine",
package: package(),
deps: deps()
Expand Down
12 changes: 12 additions & 0 deletions src/bpe.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
till/2]).

-export([assign/1,
delete/1,
complete/1,
next/1,
gw_unblock/1,
Expand Down Expand Up @@ -135,6 +136,17 @@ cleanup(P) ->
kvs:delete(writer, key("/bpe/flow/", P)),
kvs:delete("/bpe/proc", P).

delete(#process{id = Pid, parent = Parent, monitor = Mid} = Proc) ->
gw_unblock(Pid),
unsubscribe(Pid, Parent),
kvs:remove(Proc, "/bpe/proc"),
case kvs:get(key("/bpe/mon/", Mid), Pid) of
{ok, X} -> kvs:remove(X, key("/bpe/mon/", Mid));
_ -> []
end,
kvs:append(Proc#process{status = "deleted"}, "/bpe/deleted"),
Proc#process{status = "deleted"}.

current_task(#process{id = Id} = Proc) ->
case bpe:head(Id) of
[] -> {empty, bpe:first_task(Proc)};
Expand Down
25 changes: 21 additions & 4 deletions src/bpe_proc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ process_task(Stage, Proc, NoFlow) ->
{Status, {Reason, Target}, ProcState}
end.

behavior_fun_args(handle_call, Req, From, St) -> [Req, From, St];
behavior_fun_args(_, Req, _, St) -> [Req, St].

behavior_fun(asyncEvent, _) -> handle_cast;
behavior_fun(broadcastEvent, {_, broadcastEvent, #broadcastEvent{type = immediate}}) -> handle_cast;
behavior_fun(_, _) -> handle_call.

convert_api_args(proc, [Id, _ProcId]) -> {Id, get};
convert_api_args(update, [Id, _ProcId, State]) -> {Id, set, State};
convert_api_args(assign, [Id, _ProcId]) -> {Id, ensure_mon};
Expand All @@ -113,6 +120,7 @@ handle_result(T, Id, X, #process{id = Pid} = DefState) ->
handle_result(T, terminate_check(Id, X, bpe:cache(terminateLocks, {terminateLock, Pid}), DefState)).

terminate_check(_, _, #terminateLock{limit = L, counter = C}, #process{id = Pid} = DefState) when C >= L ->
logger:notice("TERMINATE LOCK LIMIT: ~tp", [Pid]),
bpe:cache(terminateLocks, {terminate, Pid}, true), {stop, normal, DefState};
terminate_check(Id, X, #terminateLock{messages=[I]}, #process{id = Pid}) when Id == I ->
bpe:cache(terminateLocks, {terminateLock, Pid}, undefined),
Expand Down Expand Up @@ -146,15 +154,19 @@ handleContinue(X, _, _) -> X.

% BPMN 2.0 Инфотех
handle_call({Id, mon_link, MID}, _, Proc) ->
logger:notice("BPE MON_LINK: ~p.", [Proc#process.id]),
ProcNew = Proc#process{monitor = MID},
handle_result(call, Id, {reply, ProcNew, ProcNew}, Proc);
handle_call({Id, ensure_mon}, _, Proc) ->
logger:notice("BPE ENSURE_MON: ~p.", [Proc#process.id]),
{Mon, ProcNew} = bpe:ensure_mon(Proc),
handle_result(call, Id, {stop, normal, Mon, ProcNew}, Proc);
handle_call({Id, get}, _, Proc) -> handle_result(call, Id, {stop, normal, Proc, Proc}, Proc);
handle_call({Id, get}, _, Proc) -> logger:notice("BPE GET: ~p.", [Proc#process.id]), handle_result(call, Id, {stop, normal, Proc, Proc}, Proc);
handle_call({Id, set, State}, _, Proc) ->
logger:notice("BPE SET: ~p.", [Proc#process.id]),
handle_result(call, Id, {stop, normal, Proc, State}, State);
handle_call({Id, persist, State}, _, #process{} = _Proc) ->
handle_call({Id, persist, State}, _, #process{} = Proc) ->
logger:notice("BPE PERSIST: ~p.", [Proc#process.id]),
kvs:append(State, "/bpe/proc"),
handle_result(call, Id, {stop, normal, State, State}, State);
handle_call({Id, next}, _, #process{} = Proc) ->
Expand Down Expand Up @@ -216,14 +228,18 @@ handle_call({Id, modify, Form, remove}, _, Proc) ->
end;

handle_call({Id, mon_link, MID, Continue}, _, Proc) ->
logger:notice("BPE MON_LINK CONTINUE: ~p.", [Proc#process.id]),
ProcNew = Proc#process{monitor = MID},
handle_result(call, Id, handleContinue({stop, normal, ProcNew, ProcNew}, Continue, Id), Proc);
handle_call({Id, ensure_mon, Continue}, _, Proc) ->
logger:notice("BPE ENSURE_MON CONTINUE: ~p.", [Proc#process.id]),
{Mon, ProcNew} = bpe:ensure_mon(Proc),
handle_result(call, Id, handleContinue({stop, normal, Mon, ProcNew}, Continue, Id), Proc);
handle_call({Id, set, State, Continue}, _, Proc) ->
logger:notice("BPE SET CONTINUE: ~p.", [Proc#process.id]),
handle_result(call, Id, handleContinue({stop, normal, Proc, State}, Continue, Id), State);
handle_call({Id, persist, State, Continue}, _, #process{} = _Proc) ->
handle_call({Id, persist, State, Continue}, _, #process{} = Proc) ->
logger:notice("BPE PERSIST CONTINUE: ~p.", [Proc#process.id]),
kvs:append(State, "/bpe/proc"),
handle_result(call, Id, handleContinue({stop, normal, State, State}, Continue, Id), State);
handle_call({Id, next, Stage, Continue}, _, Proc) ->
Expand Down Expand Up @@ -265,7 +281,8 @@ handle_continue([#continue{type=spawn, module=Module, fn=Fn, args=Args} | T], Pr
spawn(fun() -> apply(Module, Fn, Args) end),
{noreply, Proc, {continue, T}};
handle_continue([#continue{id = Id, type=bpe, fn=Fn, args=Args} | T], Proc) ->
Result = try handle_call(convert_api_args(Fn, [Id | Args]), [], Proc)
BpeArgs = convert_api_args(Fn, [Id | Args]),
Result = try apply(bpe_proc, behavior_fun(Fn, BpeArgs), behavior_fun_args(behavior_fun(Fn, BpeArgs), BpeArgs, [], Proc))
catch
_X:_Y:Z -> {stop, {error, Z}, Proc}
end,
Expand Down
3 changes: 3 additions & 0 deletions src/ext/bpe_metainfo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ metainfo() ->
#table{name = procRec, fields=record_info(fields, procRec), instance = #procRec{}},
#table{name = hist, fields=record_info(fields, hist), instance = #hist{}},
#table{name = sched, fields=record_info(fields, sched), instance = #sched{}},
#table{name = broadcastEvent, fields=record_info(fields, broadcastEvent), instance = #broadcastEvent{}},
#table{name = messageEvent, fields=record_info(fields, messageEvent), instance = #messageEvent{}},
#table{name = asyncEvent, fields=record_info(fields, asyncEvent), instance = #asyncEvent{}},
#table{name = subscription, fields=record_info(fields, subscription), instance = #subscription{}, keys=record_info(fields, subscription)},
#table{name = gw_block, fields=record_info(fields, gw_block), instance = #gw_block{}, keys=record_info(fields, gw_block)}
]}.
Expand Down

0 comments on commit fbf3b31

Please sign in to comment.