diff options
author | Robert Newson <rnewson@apache.org> | 2012-07-04 10:32:19 +0100 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2012-07-04 10:47:36 +0100 |
commit | bce1e60dcf31141f18b55e311709777b70f9a7f9 (patch) | |
tree | 141d1f1a6f7775458c4a124de6f04b9db205ad04 | |
parent | 5f93f041411a6a00c6923a19c562b77c18f9341b (diff) | |
download | couchdb-bce1e60dcf31141f18b55e311709777b70f9a7f9.tar.gz |
Handle ddoc_updated event correctly.
COUCHDB-1309 introduced a new update event of the form {ddoc_updated,
{DbName, DDocId}}. Unfortunately it did not update
couch_db_update_notifier with a clause that can marshal this to JSON
successfully, breaking all uses of [update_notification]
This commit improves event encoding so that the above renders as
{"type":"ddoc_updated","db":"DbName","id":"DDocId"}
COUCHDB-1508
-rw-r--r-- | src/couchdb/couch_db_update_notifier.erl | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/couchdb/couch_db_update_notifier.erl b/src/couchdb/couch_db_update_notifier.erl index 150eb31b5..bfa770acc 100644 --- a/src/couchdb/couch_db_update_notifier.erl +++ b/src/couchdb/couch_db_update_notifier.erl @@ -53,8 +53,8 @@ handle_event(Event, Fun) when is_function(Fun, 1) -> handle_event(Event, {Fun, FunAcc}) -> FunAcc2 = Fun(Event, FunAcc), {ok, {Fun, FunAcc2}}; -handle_event({EventAtom, DbName}, Pid) -> - Obj = {[{type, list_to_binary(atom_to_list(EventAtom))}, {db, DbName}]}, +handle_event({EventType, EventDesc}, Pid) -> + Obj = encode_event(EventType, EventDesc), ok = couch_os_process:send(Pid, Obj), {ok, Pid}. @@ -71,3 +71,12 @@ handle_info({'EXIT', _, _}, Pid) -> code_change(_OldVsn, State, _Extra) -> {ok, State}. + +encode_event(EventType, EventDesc) when is_atom(EventType) -> + encode_event(atom_to_list(EventType), EventDesc); +encode_event(EventType, EventDesc) when is_list(EventType) -> + encode_event(?l2b(EventType), EventDesc); +encode_event(EventType, {DbName, DocId}) -> + {[{type, EventType}, {db, DbName}, {id, DocId}]}; +encode_event(EventType, DbName) -> + {[{type, EventType}, {db, DbName}]}. |