From 6b22b8d06c8eac0514f7d6b2c8f9fdcff6d76792 Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Fri, 1 Dec 2023 17:25:05 +0100 Subject: [PATCH] Prefer application restarts than allowing reruns --- src/amoc.erl | 14 +++++++++++++- src/amoc_controller.erl | 3 +-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/amoc.erl b/src/amoc.erl index 72731fd7..11759666 100644 --- a/src/amoc.erl +++ b/src/amoc.erl @@ -7,7 +7,8 @@ -export([do/3, add/1, remove/2, - stop/0]). + stop/0, + reset/0]). -export_type([scenario/0]). -type scenario() :: module(). @@ -56,6 +57,17 @@ stop() -> Error -> Error end. +-spec reset() -> ok | {error, term()}. +reset() -> + case is_running_locally() of + ok -> + application:stop(?MODULE), + application:ensure_all_started(?MODULE), + ok; + Error -> + Error + end. + %% ------------------------------------------------------------------ %% Local functions %% ------------------------------------------------------------------ diff --git a/src/amoc_controller.erl b/src/amoc_controller.erl index 0408da86..7b8345d5 100644 --- a/src/amoc_controller.erl +++ b/src/amoc_controller.erl @@ -181,8 +181,7 @@ handle_info(_Msg, State) -> %% ------------------------------------------------------------------ -spec handle_start_scenario(module(), amoc_config:settings(), state()) -> {handle_call_res(), state()}. -handle_start_scenario(Scenario, Settings, #state{status = Status} = State) - when Status =:= idle; Status =:= finished -> +handle_start_scenario(Scenario, Settings, #state{status = idle} = State) -> case init_scenario(Scenario, Settings) of {ok, ScenarioState} -> NewState = State#state{last_user_id = 0,