Chicagoboss websocket error while fetching data from cache

21 views
Skip to first unread message

Rana Aich

unread,
Jul 13, 2015, 2:00:53 PM7/13/15
to chica...@googlegroups.com
I'm using a cache, to fetch and save data from 3rd party data integartor server. I have written an app for this purpose and it is working perfectly. It fetches the latest data from the server at specified intervals and writes to ETS for the time being. I have a util module that fetches the latest data from the cache and dispalys it.

In the util:
--------------------
read_record(UserId) ->
    case gen_server:call(my_cache, {reading, UserId}) of %Works fine%
        {error, not_found} ->
            jsx:encode([{ok, not_found}]);
        {ok, Reading} ->
        io:format("For the user : ~n~p~n",[UserId]),
        io:format("The Latest Readings are : ~n~p~n",[Reading])
    end.
-----------------------------

In my_cache I have:
-----------------------
handle_call({reading, UserId}, _From, #state{user_id=UserId, last_reading=_, last_status=_}) ->
    case my_reading(UserId) of  %call the function that looks up ETS with UserId%
    {error, not_found} ->
        {reply, {error, not_found}, #state{user_id=undefined, last_reading=undefined, last_status=not_found}};
    {ok, Reading} ->
        {reply, {ok, Reading}, #state{user_id=UserId, last_reading=Reading, last_status=ok}}
    end;
------------------------

So far so good. My application works perfectly. I also have another cache my_ws_cache which is wroking fine.

Now I'm calling the same cache from a Websocket.
----------------------------
handle_incoming(ServiceName, WebSocketId, Message, State) ->
    error_logger:info_msg("Incoming Message: ~p~n", [binary_to_list(Message)]),
         [Email, UniqueId] = string:tokens(binary_to_list(Message), ":"),
            case lists:member(my_sup, erlang:registered()) of
                true ->
            gen_server:call(my_ws_cache, {savewspidoremail, UniqueId, WebSocketId, Email})
            end,
            UserKey = Email ++ "-" ++ ?MYCALL1,
            case lists:member(my_sup, erlang:registered()) of
                true ->
                case gen_server:call(my_cache, {reading, UserKey}) of %this line raises case_clause error%
                    {error, not_found} ->
                        WebSocketId ! {text, "No Data for User"};
                    {ok, Reading} ->
                        WebSocketId ! {text, Reading}
                end;

                false ->
                WebSocketId ! {text, "Error Connecting My Sup"}
            end,
    {noreply, State}.
---------------------------------

And here when I try to connect my_cache from Websocket I get the case_clause error:
---------------------------------

10:22:28.455 [error] ** Boss Service Handler myapp_priv_my_websocket terminating in handle_incoming/4

   for the reason error:{case_clause,ok}

ServiceUrl: "/websocket/myapp"

WebSocketId: <0.364.0>

SessionId  : <<"61472263246cb7f4b321e997ad47ba8e523a36ac">>

Message    : <<"mye...@mail.org:Z4cmlu0JdtyDIaACnIjRmiKDP5LtF7SB">>

State    : []

** Stacktrace: [{my_priv_my_websocket,handle_incoming,5,[{file,"/Users/T316538/Documents/beluga_priv/src/websocket/app_priv_my_websocket.erl"},{line,120}]},{boss_service_worker,handle_cast,2,[{file,"src/boss/boss_service_worker.erl"},{line,173}]},{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,599}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]

------------------------------------------------


Why I'm getting {case_clause, ok} error? Any suggestion would be highly appreciated.


Thanking you all in advance.



Reply all
Reply to author
Forward
0 new messages