From e6e7275de0cf8bdd467101fbb9375af7b3e22b29 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Tue, 8 Oct 2024 13:47:43 -0400 Subject: [PATCH] Less debug and info messages to log --- app/db_sql.py | 16 +++++++++++----- app/methods/data_store_methods.py | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/db_sql.py b/app/db_sql.py index 2c38977..f630a3a 100644 --- a/app/db_sql.py +++ b/app/db_sql.py @@ -1,4 +1,4 @@ -import datetime, json, pytz, redis, secrets +import datetime, json, pytz, random, redis, secrets from timeit import default_timer as timer from app.config import settings @@ -703,8 +703,8 @@ def sql_select( ) elif table_name and field_name and field_value and not (record_id or record_id_random or sql or data): # Select all records from a table with a specific field and field value - # Updated 2023-11-30 - log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + # Updated 2024-10-08 + # log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.info('Select all records from a table with a specific field and field value') if not data: @@ -1251,7 +1251,8 @@ def redis_lookup_id_random( table_name: str, check_int_id: bool = False, log_lvl: int = logging.INFO, # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL - minutes: int = 1, + minutes: int = 8, # Expire the Redis key after 8 minutes + reset_rate: int = 10, # 1 in 10 chance of resetting the Redis key ) -> str|int|bool|None: log.setLevel(log_lvl) @@ -1270,7 +1271,7 @@ def redis_lookup_id_random( log.info(f'The int ID does not exists. Returning False. Table Name: {table_name} ID: {record_id}') return False else: - log.info(f'Not checking if the int ID exists. Returning the int ID. ID: {record_id}') + log.debug(f'Not checking if the int ID exists. Returning the int ID. ID: {record_id}') return record_id elif record_id_random is None: log.info(f'No record ID was passed. Returning None') @@ -1317,6 +1318,11 @@ def redis_lookup_id_random( # WARNING WARNING WARNING # WARNING WARNING WARNING + # To help prevent corrupt data from being stored in Redis for too long, we will set the record_id to None 25% of the time. This will force the function to look up the record_id in the database. This is a temporary solution. Why is the data from SQL not correct in the first place??? -2024-10-08 + if record_id and random.randint(1, reset_rate) == 1: + log.warning(f'Redis: Randomly (1/{reset_rate}) setting record_id to None. Key="{key_name}" value="{record_id}" TTL={r.ttl(key_name)} seconds') + record_id = None + if record_id: r.setex(key_name, datetime.timedelta(minutes=1), value=record_id) log.info(f'Redis: Entry found for: Key="{key_name}" value="{record_id}" TTL={r.ttl(key_name)} seconds') diff --git a/app/methods/data_store_methods.py b/app/methods/data_store_methods.py index 96c1743..f456f64 100644 --- a/app/methods/data_store_methods.py +++ b/app/methods/data_store_methods.py @@ -64,7 +64,7 @@ def load_data_store_obj_w_code( exclude_unset: bool = True, # NOTE: For now this is ignored model_as_dict: bool = False, # NOTE: For now this is ignored ) -> Data_Store_Base|dict|bool: - log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) log.info(f'Getting Data Store record with code: {code} for Account ID: {account_id} and For Type: {for_type} and For ID: {for_id}') @@ -112,7 +112,8 @@ def load_data_store_obj_w_code( data_store_rec_li = data_store_rec_li_result else: # [] or False data_store_rec_li = data_store_rec_li_result - log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.info(f'No Data Store records found with code: {code} for Account ID: {account_id} and For Type: {for_type} and For ID: {for_id}') log.debug(data_store_rec_li_result)