mirror of
https://github.com/btdig/dhtcrawler2.git
synced 2025-01-19 04:31:37 +00:00
add `size' function to hash_download_cache, to debug
This commit is contained in:
parent
108a1bfd1b
commit
e46c264056
@ -89,7 +89,7 @@ handle_info(timeout, State) ->
|
|||||||
schedule_next() ->
|
schedule_next() ->
|
||||||
case hash_download_cache:get_one() of
|
case hash_download_cache:get_one() of
|
||||||
{} ->
|
{} ->
|
||||||
timer:send_after(?WAIT_TIME);
|
timer:send_after(?WAIT_TIME, timeout);
|
||||||
Doc ->
|
Doc ->
|
||||||
gen_server:cast(self(), {process_hash, Doc})
|
gen_server:cast(self(), {process_hash, Doc})
|
||||||
end.
|
end.
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
-export([start_link/1,
|
-export([start_link/1,
|
||||||
stop/0,
|
stop/0,
|
||||||
insert/1,
|
insert/1,
|
||||||
|
size/0,
|
||||||
get_one/0]).
|
get_one/0]).
|
||||||
-record(state, {cache = [], max, dbpool}).
|
-record(state, {cache = [], max, dbpool}).
|
||||||
-define(SAVE_BATCH, 100).
|
-define(SAVE_BATCH, 100).
|
||||||
@ -35,6 +36,9 @@ insert(Doc) ->
|
|||||||
get_one() ->
|
get_one() ->
|
||||||
gen_server:call(srv_name(), get_one, infinity).
|
gen_server:call(srv_name(), get_one, infinity).
|
||||||
|
|
||||||
|
size() ->
|
||||||
|
gen_server:call(srv_name(), size).
|
||||||
|
|
||||||
srv_name() ->
|
srv_name() ->
|
||||||
?MODULE.
|
?MODULE.
|
||||||
|
|
||||||
@ -58,6 +62,10 @@ handle_cast({insert, Doc}, State) ->
|
|||||||
handle_cast(stop, State) ->
|
handle_cast(stop, State) ->
|
||||||
{stop, normal, State}.
|
{stop, normal, State}.
|
||||||
|
|
||||||
|
handle_call(size, _From, State) ->
|
||||||
|
#state{cache = Cache} = State,
|
||||||
|
{reply, length(Cache), State};
|
||||||
|
|
||||||
handle_call(get_one, _From, State) ->
|
handle_call(get_one, _From, State) ->
|
||||||
#state{dbpool = DBPool, cache = Cache} = State,
|
#state{dbpool = DBPool, cache = Cache} = State,
|
||||||
{Doc, NewCache} = try_load(DBPool, Cache),
|
{Doc, NewCache} = try_load(DBPool, Cache),
|
||||||
|
Loading…
Reference in New Issue
Block a user