diff --git a/app/db_sql.py b/app/db_sql.py index 389d363..3594ae6 100644 --- a/app/db_sql.py +++ b/app/db_sql.py @@ -23,6 +23,7 @@ engine = create_engine( echo = False, pool_use_lifo = True, pool_pre_ping = True, + pool_recycle = settings.DB['pool_recycle'], isolation_level = 'READ COMMITTED', connect_args = {'connect_timeout': settings.DB['connect_timeout']} ) @@ -380,20 +381,42 @@ def sql_update( return None except OperationalError as e: # Likely an unknown field or related trans.rollback() - log.error('An operational error exception happened. This is likely because there was an unknown field or similar included. Returning False') - log.exception('**** *** ** * ### BEGIN ### Operational Error Exception Happened: Returning False * ** *** ****') - log.error('^^^^ ^^^ ^^ ^ ### END ### Operational Error Exception ^ ^^ ^^^ ^^^^') + # log.error('An operational error exception happened. This is likely because there was an unknown field or similar included. Returning False') + # log.exception('**** *** ** * ### BEGIN ### Operational Error Exception Happened: Returning False * ** *** ****') + # log.error('^^^^ ^^^ ^^ ^ ### END ### Operational Error Exception ^ ^^ ^^^ ^^^^') - log.error('**** *** ** * ### BEGIN ### Operational Error Exception Details: * ** *** ****') - log.error('**** *** ** * SQL Statement: * ** *** ****') - log.error(e.statement) - log.error('**** *** ** * SQL Parameters: * ** *** ****') - log.error(e.params) - log.error('**** *** ** * SQL Origin Message: * ** *** ****') - log.error(e.orig) - log.error('**** *** ** * ### END ### Operational Error Exception Details: * ** *** ****') + # log.error('**** *** ** * ### BEGIN ### Operational Error Exception Details: * ** *** ****') + # log.error('**** *** ** * SQL Statement: * ** *** ****') + # log.error(e.statement) + # log.error('**** *** ** * SQL Parameters: * ** *** ****') + # log.error(e.params) + # log.error('**** *** ** * SQL Origin Message: * ** *** ****') + # log.error(e.orig) + # log.error('**** *** ** * ### END ### Operational Error Exception Details: * ** *** ****') - return False + # return False + + log.error('An operational error exception happened. This is likely a "MySQL server has gone away" error. Going to try again...') + log.exception('**** *** ** * ### BEGIN ### Operational Exception Happened: Trying again... * ** *** ****') + log.error('^^^^ ^^^ ^^ ^ ### END ### Operational Exception ^ ^^ ^^^ ^^^^') + + sql_connect(current_db=db) + + log.info('Now trying the query again...') + try: + # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + + log.info('2x Executing with SQL statement and data...') + result_update = db.execute(sql_update, data) + trans.commit() + except Exception as e: + log.error('Tried again an exception was raised again. Not going to try again.') + log.exception('**** *** ** * ### BEGIN ### (2x) Second Exception Happened: Returning False * ** *** ****') + log.error('^^^^ ^^^ ^^ ^ ### END ### Exception ^ ^^ ^^^ ^^^^') + return False # Not successful + else: + log.info('Successfully executed the SQL on the second try.') + pass except Exception as e: trans.rollback() log.error('An unknown exception happened. Returning False') @@ -1202,7 +1225,7 @@ def sql_delete( log.debug(dir(result)) log.debug(vars(result)) except OperationalError as e: - log.error('An operational error exception happended. This is likely a "MySQL server has gone away" error. Going to try again...') + log.error('An operational error exception happened. This is likely a "MySQL server has gone away" error. Going to try again...') log.exception('**** *** ** * ### BEGIN ### Operational Exception Happened: Trying again... * ** *** ****') log.error('^^^^ ^^^ ^^ ^ ### END ### Operational Exception ^ ^^ ^^^ ^^^^')