Skip to content

Commit

Permalink
Rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
yosukehara committed Mar 31, 2015
1 parent 6394541 commit 898e544
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions src/leo_pod_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,15 @@ handle_call(checkout, _From, #state{worker_pids = Children} = State) ->
{reply, {ok, WorkerPid}, State#state{worker_pids = NewChildren}};

handle_call({checkin, WorkerPid}, _From, #state{num_of_children = NumOfChildren,
worker_mod = WorkerMod,
num_overflow = NumOverflow,
worker_pids = Children} = State) ->
case length(Children) >= NumOfChildren of
true ->
%% send stop
%% actual stop process will happend at handle_info with DOWN
WorkerMod:stop(WorkerPid);
{reply, ok, State#state{num_overflow = NumOverflow + 1}};
false ->
void
end,
NewChildren = [WorkerPid|Children],
{reply, ok, State#state{worker_pids = NewChildren}};
NewChildren = [WorkerPid|Children],
{reply, ok, State#state{worker_pids = NewChildren}}
end;

handle_call(status, _From, #state{num_of_children = NumOfChildren,
max_overflow = MaxOverflow,
Expand All @@ -239,44 +236,35 @@ handle_call(close, _From, State) ->
%% @doc gen_server callback - Module:handle_cast(Request, State) -> Result
%%
handle_cast({checkin_async, WorkerPid}, #state{num_of_children = NumOfChildren,
worker_mod = WorkerMod,
num_overflow = NumOverflow,
worker_pids = Children} = State) ->
case length(Children) >= NumOfChildren of
true ->
%% send stop
%% actual stop process will happend at handle_info with DOWN
WorkerMod:stop(WorkerPid);
{noreply, State#state{num_overflow = NumOverflow + 1}};
false ->
void
end,
NewChildren = [WorkerPid|Children],
{noreply, State#state{worker_pids = NewChildren}};
NewChildren = [WorkerPid|Children],
{noreply, State#state{worker_pids = NewChildren}}
end;

handle_cast(_, State) ->
{noreply, State}.


%% @doc gen_server callback - Module:handle_info(Info, State) -> Result
%%
handle_info({'DOWN', MonitorRef, _Type, Pid, _Info}, #state{worker_mod = WorkerMod,
worker_args = WorkerArgs,
num_of_children = NumOfChildren,
num_overflow = NumOverflow,
worker_pids = ChildPids} = State) ->
handle_info({'DOWN', MonitorRef, _Type, Pid, _Info}, #state{worker_mod = WorkerMod,
worker_args = WorkerArgs,
worker_pids = ChildPids} = State) ->
true = erlang:demonitor(MonitorRef),

ChildPids1 = lists:delete(Pid, ChildPids),
case length(ChildPids1) >= NumOfChildren of
false ->
ChildPids2 = case start_child(WorkerMod, WorkerArgs) of
{ok, ChildPid} ->
[ChildPid|ChildPids1];
_ ->
ChildPids1
end,
{noreply, State#state{worker_pids = ChildPids2}};
true ->
{noreply, State#state{worker_pids = ChildPids1, num_overflow = NumOverflow - 1}}
end;
ChildPids2 = case start_child(WorkerMod, WorkerArgs) of
{ok, ChildPid} ->
[ChildPid|ChildPids1];
_ ->
ChildPids1
end,
{noreply, State#state{worker_pids = ChildPids2}};

handle_info(_Info, State) ->
{noreply, State}.
Expand Down

0 comments on commit 898e544

Please sign in to comment.