Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from GameAnalytics/fix_get_max_mappers
Browse files Browse the repository at this point in the history
* Crash if no nodes are in cluster
  • Loading branch information
sata authored Dec 28, 2017
2 parents 9f5b45b + 9baca77 commit b262730
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/gascheduler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
unfinished/1,
set_retry_timeout/2,
set_max_workers/2,
get_max_workers/1
get_max_workers/1
]).

%% For workers
Expand Down Expand Up @@ -123,8 +123,6 @@ set_max_workers(Name, Workers) ->
-spec get_max_workers(atom()) -> non_neg_integer().
get_max_workers(Name) ->
gen_server:call(Name, get_max_workers).



%%% For workers

Expand All @@ -139,14 +137,19 @@ init([Nodes, Client, MaxWorkers, MaxRetries]) ->
process_flag(trap_exit, true),
ok = net_kernel:monitor_nodes(true),

{ok, #state{nodes = ping_nodes(Nodes),
client = Client,
max_workers = MaxWorkers,
max_retries = MaxRetries,
retry_timeout = 1000,
pending = queue:new(),
running = [],
ticks = 0}}.
case ping_nodes(Nodes) of
[] ->
erlang:error(no_nodes_in_cluster);
Nodes ->
{ok, #state{nodes = Nodes,
client = Client,
max_workers = MaxWorkers,
max_retries = MaxRetries,
retry_timeout = 1000,
pending = queue:new(),
running = [],
ticks = 0}}
end.

handle_call({execute, MFA}, _From, State) ->
{reply, ok, execute_try(MFA, State)};
Expand Down Expand Up @@ -197,7 +200,7 @@ handle_call({set_max_workers, Workers}, _From, State) ->
{reply, ok, State#state{max_workers = Workers}};

handle_call(get_max_workers, _From, State) ->
{reply, ok, State#state.max_workers};
{reply, {ok, State#state.max_workers}, State};

handle_call(_Request, _From, State) ->
{reply, ok, State}.
Expand Down

0 comments on commit b262730

Please sign in to comment.