Skip to content

Commit

Permalink
check if db file exists before sync
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba committed Feb 16, 2021
1 parent 407151c commit 1f77e60
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lbry/wallet/server/db/elastic_sync.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import asyncio
import logging
import os
from collections import namedtuple
from multiprocessing import Process

Expand Down Expand Up @@ -59,8 +60,8 @@ async def make_es_index():


async def run(args, shard):
def itsbusy():
logging.info("shard %d: db is busy, retry")
def itsbusy(*_):
logging.info("shard %d: db is busy, retry", shard)
return True
db = apsw.Connection(args.db_path, flags=apsw.SQLITE_OPEN_READONLY | apsw.SQLITE_OPEN_URI)
db.setbusyhandler(itsbusy)
Expand All @@ -84,6 +85,10 @@ def run_elastic_sync():
args = parser.parse_args()
processes = []

if not os.path.exists(args.db_path):
logging.info("DB path doesnt exist")
return

if not asyncio.run(make_es_index()):
logging.info("ES is already initialized")
return
Expand Down

0 comments on commit 1f77e60

Please sign in to comment.