Skip to content

Commit

Permalink
avoid a race condition when quering while workers are dying
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anderson committed Jan 19, 2012
1 parent 3833e56 commit f28c831
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions ecallmgr/src/ecallmgr_call_control_sup.erl
Expand Up @@ -51,12 +51,12 @@ workers() ->
find_worker(CallID) ->
do_find_worker(workers(), CallID).

do_find_worker([], _) ->
do_find_worker([], _CallId) ->
{error, not_found};
do_find_worker([Srv|T], CallID) ->
case ecallmgr_call_control:callid(Srv) of
case catch(ecallmgr_call_control:callid(Srv)) of
CallID -> {ok, Srv};
_ -> do_find_worker(T, CallID)
_E -> do_find_worker(T, CallID)
end.

-spec find_control_queue/1 :: (ne_binary()) -> {'error', 'not_found'} | {'ok', ne_binary()}.
Expand Down
2 changes: 1 addition & 1 deletion ecallmgr/src/ecallmgr_call_event_sup.erl
Expand Up @@ -60,7 +60,7 @@ find_worker(CallId) ->
do_find_worker([], _) ->
{error, not_found};
do_find_worker([Srv|T], CallId) ->
case ecallmgr_call_events:callid(Srv) of
case catch(ecallmgr_call_events:callid(Srv)) of
CallId -> {ok, Srv};
_ -> do_find_worker(T, CallId)
end.
Expand Down
48 changes: 24 additions & 24 deletions ecallmgr/src/ecallmgr_call_events.erl
Expand Up @@ -57,7 +57,7 @@ start_link(Node, CallId) ->

-spec callid/1 :: (pid()) -> ne_binary().
callid(Srv) ->
gen_server:call(Srv, {callid}).
gen_server:call(Srv, {callid}, 100).

transfer(Srv, TransferType, Props) ->
gen_listener:cast(Srv, {TransferType, Props}).
Expand Down Expand Up @@ -257,29 +257,29 @@ create_event(EventName, ApplicationName, Props) ->
{Mega,Sec,Micro} = erlang:now(),
Timestamp = wh_util:to_binary(((Mega * 1000000 + Sec) * 1000000 + Micro)),
Event = [ KV || {_, V}=KV <- [{<<"Msg-ID">>, props:get_value(<<"Event-Date-Timestamp">>, Props, Timestamp)}
,{<<"Timestamp">>, props:get_value(<<"Event-Date-Timestamp">>, Props, Timestamp)}
,{<<"Call-ID">>, props:get_value(<<"Caller-Unique-ID">>, Props)}
,{<<"Call-Direction">>, props:get_value(<<"Call-Direction">>, Props)}
,{<<"Channel-Call-State">>, props:get_value(<<"Channel-Call-State">>, Props)}
,{<<"Channel-State">>, get_channel_state(Props)}
,{<<"Transfer-History">>, get_transfer_history(Props)}
,{<<"Hangup-Cause">>, get_hangup_cause(Props)}
,{<<"Hangup-Code">>, get_hangup_code(Props)}
,{<<"Disposition">>, get_disposition(Props)}
,{<<"Other-Leg-Direction">>, props:get_value(<<"Other-Leg-Direction">>, Props)}
,{<<"Other-Leg-Caller-ID-Name">>, props:get_value(<<"Other-Leg-Caller-ID-Name">>, Props)}
,{<<"Other-Leg-Caller-ID-Number">>, props:get_value(<<"Other-Leg-Caller-ID-Number">>, Props)}
,{<<"Other-Leg-Destination-Number">>, props:get_value(<<"Other-Leg-Destination-Number">>, Props)}
,{<<"Other-Leg-Unique-ID">>, props:get_value(<<"Other-Leg-Unique-ID">>, Props,
props:get_value(<<"variable_holding_uuid">>, Props))}
,{<<"Custom-Channel-Vars">>, wh_json:from_list(CCVs)}
%% this sucks, its leaky but I dont see a better way around it since we need the raw application
%% name in call_control... (see note in call_control on start_link for why we need to use AMQP
%% to communicate to it)
,{<<"Raw-Application-Name">>, props:get_value(<<"Application">>, Props, ApplicationName)}
| event_specific(EventName, ApplicationName, Props)
],
V =/= undefined],
,{<<"Timestamp">>, props:get_value(<<"Event-Date-Timestamp">>, Props, Timestamp)}
,{<<"Call-ID">>, props:get_value(<<"Caller-Unique-ID">>, Props)}
,{<<"Call-Direction">>, props:get_value(<<"Call-Direction">>, Props)}
,{<<"Channel-Call-State">>, props:get_value(<<"Channel-Call-State">>, Props)}
,{<<"Channel-State">>, get_channel_state(Props)}
,{<<"Transfer-History">>, get_transfer_history(Props)}
,{<<"Hangup-Cause">>, get_hangup_cause(Props)}
,{<<"Hangup-Code">>, get_hangup_code(Props)}
,{<<"Disposition">>, get_disposition(Props)}
,{<<"Other-Leg-Direction">>, props:get_value(<<"Other-Leg-Direction">>, Props)}
,{<<"Other-Leg-Caller-ID-Name">>, props:get_value(<<"Other-Leg-Caller-ID-Name">>, Props)}
,{<<"Other-Leg-Caller-ID-Number">>, props:get_value(<<"Other-Leg-Caller-ID-Number">>, Props)}
,{<<"Other-Leg-Destination-Number">>, props:get_value(<<"Other-Leg-Destination-Number">>, Props)}
,{<<"Other-Leg-Unique-ID">>, props:get_value(<<"Other-Leg-Unique-ID">>, Props,
props:get_value(<<"variable_holding_uuid">>, Props))}
,{<<"Custom-Channel-Vars">>, wh_json:from_list(CCVs)}
%% this sucks, its leaky but I dont see a better way around it since we need the raw application
%% name in call_control... (see note in call_control on start_link for why we need to use AMQP
%% to communicate to it)
,{<<"Raw-Application-Name">>, props:get_value(<<"Application">>, Props, ApplicationName)}
| event_specific(EventName, ApplicationName, Props)
],
V =/= undefined],
wh_api:default_headers(<<>>, ?EVENT_CAT, EventName, ?APP_NAME, ?APP_VERSION) ++ Event.

-spec publish_event/1 :: (proplist()) -> 'ok'.
Expand Down

0 comments on commit f28c831

Please sign in to comment.