Skip to content

Commit

Permalink
KAZOO-3708: update milliwatt so it is not using a shared q
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anderson committed May 20, 2015
1 parent 9e349a0 commit 3cbd7ac
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 54 deletions.
29 changes: 17 additions & 12 deletions applications/ecallmgr/src/ecallmgr_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1020,26 +1020,31 @@ request_media_url(MediaName, CallId, JObj, Type) ->
,{<<"Msg-ID">>, wh_util:to_binary(wh_util:current_tstamp())}
| wh_api:default_headers(<<"media">>, <<"media_req">>, ?APP_NAME, ?APP_VERSION)
])
,JObj
),
ReqResp = wh_amqp_worker:call(Request
,fun wapi_media:publish_req/1
,fun wapi_media:resp_v/1
),
case ReqResp of
{'error', _E}=E ->
lager:debug("error get media url from amqp ~p", [E]),
E;
,JObj),
case wh_amqp_worker:call_collect(Request
,fun wapi_media:publish_req/1
,{'media_mgr', fun wapi_media:resp_v/1}
)
of
{'ok', MediaResp} ->
MediaUrl = wh_json:get_value(<<"Stream-URL">>, MediaResp, <<>>),
MediaUrl = wh_json:find(<<"Stream-URL">>, MediaResp, <<>>),
CacheProps = media_url_cache_props(MediaName),
_ = wh_cache:store_local(?ECALLMGR_UTIL_CACHE
,?ECALLMGR_PLAYBACK_MEDIA_KEY(MediaName)
,MediaUrl
,CacheProps
),
lager:debug("media ~s stored to playback cache : ~s", [MediaName, MediaUrl]),
{'ok', MediaUrl}
{'ok', MediaUrl};
{'returned', _JObj, _BR} ->
lager:debug("no media manager available", []),
{'error', 'timeout'};
{'timeout', _Resp} ->
lager:debug("timeout when getting media url from amqp", []),
{'error', 'timeout'};
{'error', _R}=E ->
lager:debug("error when getting media url from amqp ~p", [_R]),
E
end.

-define(DEFAULT_MEDIA_CACHE_PROPS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
%%% @contributors
%%% Peter Defebvre
%%%-------------------------------------------------------------------
-module(milliwatt_shared_listener).
-module(milliwatt_listener).

-behaviour(gen_listener).

Expand All @@ -24,15 +24,15 @@

-record(state, {}).

-define(BINDINGS, [{route, []}
,{self, []}
-define(BINDINGS, [{'route', []}
,{'self', []}
]).
-define(RESPONDERS, [{milliwatt_route_req, [{<<"dialplan">>, <<"route_req">>}]}
,{milliwatt_route_win, [{<<"dialplan">>, <<"route_win">>}]}
-define(RESPONDERS, [{'milliwatt_route_req', [{<<"dialplan">>, <<"route_req">>}]}
,{'milliwatt_route_win', [{<<"dialplan">>, <<"route_win">>}]}
]).
-define(QUEUE_NAME, <<"milliwatt_listener">>).
-define(QUEUE_OPTIONS, [{'exclusive', 'false'}]).
-define(CONSUME_OPTIONS, [{'exclusive', 'false'}]).
-define(QUEUE_NAME, <<>>).
-define(QUEUE_OPTIONS, []).
-define(CONSUME_OPTIONS, []).

%%%===================================================================
%%% API
Expand All @@ -46,11 +46,11 @@
%% @end
%%--------------------------------------------------------------------
start_link() ->
gen_listener:start_link(?MODULE, [{bindings, ?BINDINGS}
,{responders, ?RESPONDERS}
,{queue_name, ?QUEUE_NAME} % optional to include
,{queue_options, ?QUEUE_OPTIONS} % optional to include
,{consume_options, ?CONSUME_OPTIONS} % optional to include
gen_listener:start_link(?MODULE, [{'bindings', ?BINDINGS}
,{'responders', ?RESPONDERS}
,{'queue_name', ?QUEUE_NAME}
,{'queue_options', ?QUEUE_OPTIONS}
,{'consume_options', ?CONSUME_OPTIONS}
], []).

%%%===================================================================
Expand All @@ -69,7 +69,7 @@ start_link() ->
%% @end
%%--------------------------------------------------------------------
init([]) ->
{ok, #state{}}.
{'ok', #state{}}.

%%--------------------------------------------------------------------
%% @private
Expand All @@ -86,7 +86,7 @@ init([]) ->
%% @end
%%--------------------------------------------------------------------
handle_call(_Request, _From, State) ->
{reply, {error, not_implemented}, State}.
{'reply', {'error', 'not_implemented'}, State}.

%%--------------------------------------------------------------------
%% @private
Expand All @@ -99,7 +99,7 @@ handle_call(_Request, _From, State) ->
%% @end
%%--------------------------------------------------------------------
handle_cast(_Msg, State) ->
{noreply, State}.
{'noreply', State}.

%%--------------------------------------------------------------------
%% @private
Expand All @@ -112,7 +112,7 @@ handle_cast(_Msg, State) ->
%% @end
%%--------------------------------------------------------------------
handle_info(_Info, State) ->
{noreply, State}.
{'noreply', State}.

%%--------------------------------------------------------------------
%% @private
Expand All @@ -123,7 +123,7 @@ handle_info(_Info, State) ->
%% @end
%%--------------------------------------------------------------------
handle_event(_JObj, _State) ->
{reply, []}.
{'reply', []}.

%%--------------------------------------------------------------------
%% @private
Expand All @@ -148,7 +148,7 @@ terminate(_Reason, _State) ->
%% @end
%%--------------------------------------------------------------------
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
{'ok', State}.

%%%===================================================================
%%% Internal functions
Expand Down
24 changes: 10 additions & 14 deletions applications/milliwatt/src/milliwatt_route_req.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@

-define(CONFLICT_ACTION, 'tone').

-define(TONE, wh_json:from_list([
{<<"caller_id">>,[]}
,{<<"number">>,[<<"5555555551">>]}
])).
-define(ECHO, wh_json:from_list([
{<<"caller_id">>,[]}
,{<<"number">>,[<<"5555555552">>]}
])).
-define(TONE, wh_json:from_list(
[{<<"caller_id">>,[]}
,{<<"number">>,[<<"5555555551">>]}
])
).
-define(ECHO, wh_json:from_list(
[{<<"caller_id">>,[]}
,{<<"number">>,[<<"5555555552">>]}
])
).


handle_req(JObj, Props) ->
Expand Down Expand Up @@ -106,9 +108,3 @@ rule_exist(JObj, To, From) ->
{'false', 'false'} -> 'false';
_ -> 'true'
end.






13 changes: 4 additions & 9 deletions applications/milliwatt/src/milliwatt_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@

-behaviour(supervisor).

-include_lib("whistle/include/wh_types.hrl").
-include("milliwatt.hrl").

-export([start_link/0]).
-export([init/1]).

%% Helper macro for declaring children of supervisor
-define(CHILD(Name, Type), fun(N, cache) -> {N, {wh_cache, start_link, [N]}, permanent, 5000, worker, [wh_cache]};
(N, T) -> {N, {N, start_link, []}, permanent, 5000, T, [N]} end(Name, Type)).
-define(CHILDREN, [{milliwatt_shared_listener, worker}]).
-define(CHILDREN, [?WORKER('milliwatt_listener')]).

%% ===================================================================
%% API functions
Expand All @@ -32,7 +29,7 @@
%%--------------------------------------------------------------------
-spec start_link() -> startlink_ret().
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
supervisor:start_link({'local', ?MODULE}, ?MODULE, []).

%% ===================================================================
%% Supervisor callbacks
Expand All @@ -55,6 +52,4 @@ init([]) ->
MaxSecondsBetweenRestarts = 10,

SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},
Children = [?CHILD(Name, Type) || {Name, Type} <- ?CHILDREN],

{'ok', {SupFlags, Children}}.
{'ok', {SupFlags, ?CHILDREN}}.

0 comments on commit 3cbd7ac

Please sign in to comment.