check if db file exists before sync

This commit is contained in:
Victor Shyba 2021-02-16 12:52:32 -03:00
parent a9a0ac92d7
commit a916c1f4ad

View file

@ -1,6 +1,7 @@
import argparse import argparse
import asyncio import asyncio
import logging import logging
import os
from collections import namedtuple from collections import namedtuple
from multiprocessing import Process from multiprocessing import Process
@ -59,8 +60,8 @@ async def make_es_index():
async def run(args, shard): async def run(args, shard):
def itsbusy(): def itsbusy(*_):
logging.info("shard %d: db is busy, retry") logging.info("shard %d: db is busy, retry", shard)
return True return True
db = apsw.Connection(args.db_path, flags=apsw.SQLITE_OPEN_READONLY | apsw.SQLITE_OPEN_URI) db = apsw.Connection(args.db_path, flags=apsw.SQLITE_OPEN_READONLY | apsw.SQLITE_OPEN_URI)
db.setbusyhandler(itsbusy) db.setbusyhandler(itsbusy)
@ -84,6 +85,10 @@ def run_elastic_sync():
args = parser.parse_args() args = parser.parse_args()
processes = [] processes = []
if not os.path.exists(args.db_path):
logging.info("DB path doesnt exist")
return
if not asyncio.run(make_es_index()): if not asyncio.run(make_es_index()):
logging.info("ES is already initialized") logging.info("ES is already initialized")
return return