process_fts_updates: Clean up logging output.

This saves a couple lines of spammy output in the run-dev.py startup
experience, and will be better output in production as well.
This commit is contained in:
Tim Abbott
2020-05-01 11:51:18 -07:00
parent ce55ef6e4f
commit 4f3976b917
2 changed files with 23 additions and 11 deletions

View File

@@ -22,6 +22,7 @@ try:
except ImportError:
pass
import argparse
import psycopg2
import psycopg2.extensions
import select
@@ -33,6 +34,19 @@ import os
BATCH_SIZE = 1000
parser = argparse.ArgumentParser()
parser.add_argument('--quiet',
action='store_true')
options = parser.parse_args()
logging.Formatter.converter = time.gmtime
logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s")
logger = logging.getLogger("process_fts_updates")
if options.quiet:
logger.setLevel(logging.INFO)
else:
logger.setLevel(logging.DEBUG)
def update_fts_columns(cursor: psycopg2.extensions.cursor) -> int:
cursor.execute("SELECT id, message_id FROM fts_update_log LIMIT %s;" % (
BATCH_SIZE,))
@@ -55,13 +69,6 @@ def am_master(cursor: psycopg2.extensions.cursor) -> bool:
cursor.execute("SELECT pg_is_in_recovery()")
return not cursor.fetchall()[0][0]
logging.Formatter.converter = time.gmtime
logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s")
logger = logging.getLogger("process_fts_updates")
logger.setLevel(logging.DEBUG)
logger.info("process_fts_updates starting")
pg_args = {}
# Path to the root of the Zulip codebase in production
@@ -124,16 +131,21 @@ while True:
while not am_master(cursor):
if first_check:
first_check = False
logger.info("In recovery; sleeping")
logger.warning("In recovery; sleeping")
time.sleep(5)
logger.info("Not in recovery; listening for FTS updates")
logger.info("process_fts_updates: listening for search index updates")
cursor.execute("LISTEN fts_update_log;")
# Catch up on any historical columns
while True:
rows_updated = update_fts_columns(cursor)
logger.info("Processed %s rows catching up" % (rows_updated,))
notice = "Processed %s rows catching up" % (rows_updated,)
if rows_updated > 0:
logger.info(notice)
else:
logger.debug(notice)
if rows_updated != BATCH_SIZE:
# We're caught up, so proceed to the listening for updates phase.
break