make database syncing asynchronous
This commit is contained in:
parent
db9eb0236b
commit
92ee219ffc
1 changed files with 9 additions and 5 deletions
|
@ -177,8 +177,12 @@ async def try_ip(db, server_ip, checks, opts: Options):
|
||||||
|
|
||||||
|
|
||||||
async def sync_database(db, opts: Options):
|
async def sync_database(db, opts: Options):
|
||||||
# TODO: handle addresses that were removed from respodns.ips.china.
|
|
||||||
from .ips import china, blocks
|
from .ips import china, blocks
|
||||||
|
|
||||||
|
if db is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
# TODO: handle addresses that were removed from respodns.ips.china.
|
||||||
for ips, kw in ((china, "china"), (blocks, "block_target")):
|
for ips, kw in ((china, "china"), (blocks, "block_target")):
|
||||||
for ip in ips:
|
for ip in ips:
|
||||||
kwargs = dict()
|
kwargs = dict()
|
||||||
|
@ -193,11 +197,10 @@ async def sync_database(db, opts: Options):
|
||||||
async def main(db, filepath, checks, opts: Options):
|
async def main(db, filepath, checks, opts: Options):
|
||||||
from .ip_util import read_ips
|
from .ip_util import read_ips
|
||||||
from .util import make_pooler
|
from .util import make_pooler
|
||||||
from asyncio import sleep
|
from asyncio import sleep, create_task
|
||||||
from sys import stdin
|
from sys import stdin, stderr
|
||||||
|
|
||||||
if db is not None:
|
syncing = create_task(sync_database(db, opts))
|
||||||
await sync_database(db, opts)
|
|
||||||
|
|
||||||
def finisher(done, pending):
|
def finisher(done, pending):
|
||||||
for task in done:
|
for task in done:
|
||||||
|
@ -226,3 +229,4 @@ async def main(db, filepath, checks, opts: Options):
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
await pooler()
|
await pooler()
|
||||||
|
await syncing
|
||||||
|
|
Loading…
Reference in a new issue