diff --git a/src/hash_reader/hash_download.erl b/src/hash_reader/hash_download.erl index cac0044..2fc76e4 100644 --- a/src/hash_reader/hash_download.erl +++ b/src/hash_reader/hash_download.erl @@ -89,7 +89,7 @@ handle_info(timeout, State) -> schedule_next() -> case hash_download_cache:get_one() of {} -> - timer:send_after(?WAIT_TIME); + timer:send_after(?WAIT_TIME, timeout); Doc -> gen_server:cast(self(), {process_hash, Doc}) end. diff --git a/src/hash_reader/hash_download_cache.erl b/src/hash_reader/hash_download_cache.erl index bf1cdf5..653bb01 100644 --- a/src/hash_reader/hash_download_cache.erl +++ b/src/hash_reader/hash_download_cache.erl @@ -18,6 +18,7 @@ -export([start_link/1, stop/0, insert/1, + size/0, get_one/0]). -record(state, {cache = [], max, dbpool}). -define(SAVE_BATCH, 100). @@ -35,6 +36,9 @@ insert(Doc) -> get_one() -> gen_server:call(srv_name(), get_one, infinity). +size() -> + gen_server:call(srv_name(), size). + srv_name() -> ?MODULE. @@ -58,6 +62,10 @@ handle_cast({insert, Doc}, State) -> handle_cast(stop, State) -> {stop, normal, State}. +handle_call(size, _From, State) -> + #state{cache = Cache} = State, + {reply, length(Cache), State}; + handle_call(get_one, _From, State) -> #state{dbpool = DBPool, cache = Cache} = State, {Doc, NewCache} = try_load(DBPool, Cache),