diff options
Diffstat (limited to 'src/fabric_rpc.erl')
-rw-r--r-- | src/fabric_rpc.erl | 49 |
1 files changed, 15 insertions, 34 deletions
diff --git a/src/fabric_rpc.erl b/src/fabric_rpc.erl index fd54827c..0a034d59 100644 --- a/src/fabric_rpc.erl +++ b/src/fabric_rpc.erl @@ -1,49 +1,30 @@ -module(fabric_rpc). --export([open_doc/4, get_doc_info/1]). --export([receive_loop/3]). +-export([open_doc/4, get_db_info/1]). --include("../../dynomite/include/membership.hrl"). +%% rpc endpoints +%% call to with_db will supply your M:F with a #db{} and then remaining args open_doc(DbName, DocId, Revs, Options) -> - case couch_db:open(DbName, []) of - {ok, Db} -> - try - couch_api:open_doc(Db, DocId, Revs, Options) - after - couch_db:close(Db) - end; - {not_found, no_db_file} -> - throw({not_found, <<"The database does not exist.">>}); - Error -> - throw(Error) - end. + with_db(DbName, {couch_api, open_doc, [DocId, Revs, Options]}). + +get_db_info(DbName) -> + with_db(DbName, {couch_db, get_db_info, []}). -get_doc_info(DbName) -> +%% +%% internal +%% + +with_db(DbName, {M,F,A}) -> case couch_db:open(DbName, []) of {ok, Db} -> - try - couch_db:get_db_info(Db) - after - couch_db:close(Db) - end; - {not_found, no_db_file} -> - throw({not_found, <<"The database does not exist.">>}); + rexi:reply(apply(M, F, [Db | A])); Error -> - throw(Error) + rexi:reply(Error) end. + %% %% helper funs %% - -%% @doc set up the receive loop with an overall timeout --spec receive_loop([ref_part_map()], integer(), function()) -> {ok, beg_acc()}. -receive_loop(RefPartMap, Timeout, Loop) -> - TimeoutRef = erlang:make_ref(), - {ok, TRef} = timer:send_after(Timeout, {timeout, TimeoutRef}), - Results = Loop(RefPartMap, TimeoutRef, []), - timer:cancel(TRef), - Results. -%{Status, Info} = couch_db:get_db_info(Shard), |