diff options
author | benoitc <bchesneau@gmail.com> | 2014-02-13 16:37:35 +0100 |
---|---|---|
committer | benoitc <bchesneau@gmail.com> | 2014-02-13 16:37:35 +0100 |
commit | ae6eae31a1f08b7116c3b47257fd34a01287427f (patch) | |
tree | 29f4872a95792bb7331259d90f469a58eccca5ec | |
parent | 81332b78ab2152af555c7d7d78ec8e878c07fc3a (diff) | |
download | couchdb-ae6eae31a1f08b7116c3b47257fd34a01287427f.tar.gz |
remove couch_dbupdates
-rw-r--r-- | apps/couch_dbupdates/src/couch_dbupdates.app.src | 11 | ||||
-rw-r--r-- | apps/couch_dbupdates/src/couch_dbupdates.erl | 46 | ||||
-rw-r--r-- | apps/couch_dbupdates/src/couch_dbupdates_httpd.erl | 69 |
3 files changed, 0 insertions, 126 deletions
diff --git a/apps/couch_dbupdates/src/couch_dbupdates.app.src b/apps/couch_dbupdates/src/couch_dbupdates.app.src deleted file mode 100644 index 54a543ea3..000000000 --- a/apps/couch_dbupdates/src/couch_dbupdates.app.src +++ /dev/null @@ -1,11 +0,0 @@ -{application, couch_dbupdates, - [ - {description, ""}, - {vsn, "1.0.0"}, - {registered, []}, - {applications, [ - kernel, - stdlib - ]}, - {env, []} - ]}. diff --git a/apps/couch_dbupdates/src/couch_dbupdates.erl b/apps/couch_dbupdates/src/couch_dbupdates.erl deleted file mode 100644 index e37362f43..000000000 --- a/apps/couch_dbupdates/src/couch_dbupdates.erl +++ /dev/null @@ -1,46 +0,0 @@ --module(couch_dbupdates). - --export([handle_dbupdates/3]). - - -handle_dbupdates(Fun, Acc, Options) -> - NotifierPid = db_update_notifier(), - try - loop(Fun, Acc, Options) - after - couch_db_update_notifier:stop(NotifierPid) - end. - - -loop(Fun, Acc, Options) -> - [{timeout, Timeout}, {heartbeat, Heartbeat}] = Options, - receive - {db_updated, Event} -> - case Fun(Event, Acc) of - {ok, Acc1} -> - loop(Fun, Acc1, Options); - stop -> - Fun(stop, Acc) - - end - after Timeout -> - case Heartbeat of - true -> - case Fun(heartbeat, Acc) of - {ok, Acc1} -> - loop(Fun, Acc1, Options); - stop -> - Fun(stop, Acc) - - end; - _ -> - Fun(stop, Acc) - end - end. - -db_update_notifier() -> - Self = self(), - {ok, Notifier} = couch_db_update_notifier:start_link(fun(Event) -> - Self ! {db_updated, Event} - end), - Notifier. diff --git a/apps/couch_dbupdates/src/couch_dbupdates_httpd.erl b/apps/couch_dbupdates/src/couch_dbupdates_httpd.erl deleted file mode 100644 index 09f11047a..000000000 --- a/apps/couch_dbupdates/src/couch_dbupdates_httpd.erl +++ /dev/null @@ -1,69 +0,0 @@ --module(couch_dbupdates_httpd). - --export([handle_req/1]). - --include_lib("couch/include/couch_db.hrl"). - --record(state, {resp, feed}). - -handle_req(#httpd{method='GET'}=Req) -> - ok = couch_httpd:verify_is_server_admin(Req), - Qs = couch_httpd:qs(Req), - Feed = proplists:get_value("feed", Qs, "longpoll"), - - Timeout = list_to_integer( - proplists:get_value("timeout", Qs, "60000") - ), - - Heartbeat0 = proplists:get_value("heartbeat", Qs), - Heartbeat = case {Feed, Heartbeat0} of - {"longpoll", _} -> false; - {_, "false"} -> false; - _ -> true - end, - - Options = [{timeout, Timeout}, {heartbeat, Heartbeat}], - - {ok, Resp} = case Feed of - "eventsource" -> - Headers = [ - {"Content-Type", "text/event-stream"}, - {"Cache-Control", "no-cache"} - ], - couch_httpd:start_json_response(Req, 200, Headers); - _ -> - couch_httpd:start_json_response(Req, 200) - end, - - State = #state{resp=Resp, feed=Feed}, - couch_dbupdates:handle_dbupdates(fun handle_update/2, - State, Options); - -handle_req(Req) -> - couch_httpd:send_method_not_allowed(Req, "GET"). - -handle_update(stop, #state{resp=Resp}) -> - couch_httpd:end_json_response(Resp); -handle_update(heartbeat, #state{resp=Resp}=State) -> - {ok, Resp1} = couch_httpd:send_chunk(Resp, "\n"), - {ok, State#state{resp=Resp1}}; -handle_update(Event, #state{resp=Resp, feed="eventsource"}=State) -> - EventObj = event_obj(Event), - {ok, Resp1} = couch_httpd:send_chunk(Resp, ["data: ", - ?JSON_ENCODE(EventObj), - "\n\n"]), - {ok, State#state{resp=Resp1}}; -handle_update(Event, #state{resp=Resp, feed="continuous"}=State) -> - EventObj = event_obj(Event), - {ok, Resp1} = couch_httpd:send_chunk(Resp, [?JSON_ENCODE(EventObj) | - "\n"]), - {ok, State#state{resp=Resp1}}; -handle_update(Event, #state{resp=Resp, feed="longpoll"}) -> - {Props} = event_obj(Event), - JsonObj = {[{<<"ok">>, true} | Props]}, - couch_httpd:send_chunk(Resp, ?JSON_ENCODE(JsonObj)), - stop. - -event_obj({Type, DbName}) -> - {[{<<"type">>, couch_util:to_binary(Type)}, - {<<"db_name">>, couch_util:to_binary(DbName)}]}. |