make database syncing asynchronous

This commit is contained in:
Connor Olding 2020-09-04 13:08:04 +02:00
parent db9eb0236b
commit 92ee219ffc

View File

@ -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