mirror of
https://github.com/btdig/dhtcrawler2.git
synced 2025-01-19 04:31:37 +00:00
hash_reader now use findAndModify to read and delete hash/wait_download
This commit is contained in:
parent
356a1c0a92
commit
539dd9103b
@ -205,28 +205,23 @@ insert_to_download_wait(Conn, Doc) ->
|
|||||||
end).
|
end).
|
||||||
|
|
||||||
try_next_download(Conn) ->
|
try_next_download(Conn) ->
|
||||||
Doc = mongo:do(safe, master, Conn, ?HASH_DBNAME, fun() ->
|
Doc = load_delete_next(Conn, ?HASH_DOWNLOAD_COLL),
|
||||||
D = mongo:find_one(?HASH_DOWNLOAD_COLL, {}),
|
|
||||||
delete_inner_doc(?HASH_DOWNLOAD_COLL, D),
|
|
||||||
D
|
|
||||||
end),
|
|
||||||
schedule_next(Doc, true).
|
schedule_next(Doc, true).
|
||||||
|
|
||||||
% if there's no hash, try `wait_download'
|
% if there's no hash, try `wait_download'
|
||||||
try_next(Conn) ->
|
try_next(Conn) ->
|
||||||
Doc = mongo:do(safe, master, Conn, ?HASH_DBNAME, fun() ->
|
Doc = load_delete_next(Conn, ?HASH_COLLNAME),
|
||||||
D = mongo:find_one(?HASH_COLLNAME, {}),
|
|
||||||
delete_inner_doc(?HASH_COLLNAME, D),
|
|
||||||
D
|
|
||||||
end),
|
|
||||||
schedule_next(Doc, false).
|
schedule_next(Doc, false).
|
||||||
|
|
||||||
delete_inner_doc(_Col, {}) ->
|
load_delete_next(Conn, Col) ->
|
||||||
ok;
|
Cmd = {findAndModify, Col, fields, {}, remove, true},
|
||||||
|
Ret = mongo:do(safe, master, Conn, ?HASH_DBNAME, fun() ->
|
||||||
delete_inner_doc(Col, {Doc}) ->
|
mongo:command(Cmd)
|
||||||
{ID} = bson:lookup('_id', Doc),
|
end),
|
||||||
mongo:delete(Col, {'_id', ID}).
|
case Ret of
|
||||||
|
{value, undefined, ok, 1.0} -> {};
|
||||||
|
{value, Obj, lastErrorObject, _, ok, 1.0} -> {Obj}
|
||||||
|
end.
|
||||||
|
|
||||||
schedule_next({}, true) ->
|
schedule_next({}, true) ->
|
||||||
ok;
|
ok;
|
||||||
|
Loading…
Reference in New Issue
Block a user