Merge branch 'warning-non-flushed-mysql-cache' into test-v3
This commit is contained in:
15
mysqlred.py
15
mysqlred.py
@@ -31,6 +31,8 @@ try:
|
||||
except ImportError:
|
||||
import MySQLdb as mysqldb
|
||||
|
||||
import atexit
|
||||
|
||||
from pywikibot import config
|
||||
|
||||
import jogobot
|
||||
@@ -73,6 +75,9 @@ class MysqlRed:
|
||||
passwd=type( self ).db_password,
|
||||
db=type( self ).db_name )
|
||||
|
||||
# Register callback for warnig if exit with cached db write querys
|
||||
atexit.register( type(self).warn_if_not_flushed )
|
||||
|
||||
def __del__( self ):
|
||||
"""
|
||||
Before deleting class, close connection to MySQL-DB
|
||||
@@ -108,6 +113,16 @@ class MysqlRed:
|
||||
if cls._cached_insert_data or cls._cached_update_data:
|
||||
cls.connection.commit()
|
||||
|
||||
@classmethod
|
||||
def warn_if_not_flushed(cls):
|
||||
"""
|
||||
Outputs a warning if there are db write querys cached and not flushed
|
||||
before exiting programm!
|
||||
"""
|
||||
if cls._cached_update_data or cls._cached_insert_data:
|
||||
jogobot.output( "Cached Database write querys not flushed!!! " +
|
||||
"Data loss is possible!", "WARNING" )
|
||||
|
||||
|
||||
class MysqlRedPage( MysqlRed ):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user