diff --git a/src/dmt_api.erl b/src/dmt_api.erl index 11936bd..cdee09c 100644 --- a/src/dmt_api.erl +++ b/src/dmt_api.erl @@ -116,9 +116,7 @@ apply_commit(VersionWas, #'Commit'{ops = Ops}, History) -> -spec start(application:start_type(), term()) -> {ok, pid()} | {error, term()}. start(_StartType, _Args) -> - {ok, Pid} = supervisor:start_link({local, ?MODULE}, ?MODULE, []), - {ok, _Context} = dmt_api_mg:start(dmt_api_context:new()), - {ok, Pid}. + supervisor:start_link({local, ?MODULE}, ?MODULE, []). -spec stop(term()) -> ok. diff --git a/src/dmt_api_mg.erl b/src/dmt_api_mg.erl index e5a4682..730b202 100644 --- a/src/dmt_api_mg.erl +++ b/src/dmt_api_mg.erl @@ -72,7 +72,13 @@ commit(Version, Commit, Context) -> call(Method, Args, Context) -> Request = {{dmsl_state_processing_thrift, 'Automaton'}, Method, [?NS | Args]}, {ok, URL} = application:get_env(dmt_api, automaton_service_url), - woody_client:call(Context, Request, #{url => URL}). + try + woody_client:call(Context, Request, #{url => URL}) + catch + throw:{{exception, #'MachineNotFound'{}}, Context1} -> + {ok, Context2} = start(Context1), + woody_client:call(Context2, Request, #{url => URL}) + end. %% utils