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):
|
||||
# TODO: handle addresses that were removed from respodns.ips.china.
|
||||
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 ip in ips:
|
||||
kwargs = dict()
|
||||
|
@ -193,11 +197,10 @@ async def sync_database(db, opts: Options):
|
|||
async def main(db, filepath, checks, opts: Options):
|
||||
from .ip_util import read_ips
|
||||
from .util import make_pooler
|
||||
from asyncio import sleep
|
||||
from sys import stdin
|
||||
from asyncio import sleep, create_task
|
||||
from sys import stdin, stderr
|
||||
|
||||
if db is not None:
|
||||
await sync_database(db, opts)
|
||||
syncing = create_task(sync_database(db, opts))
|
||||
|
||||
def finisher(done, pending):
|
||||
for task in done:
|
||||
|
@ -226,3 +229,4 @@ async def main(db, filepath, checks, opts: Options):
|
|||
f.close()
|
||||
|
||||
await pooler()
|
||||
await syncing
|
||||
|
|
Loading…
Reference in a new issue