mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user