def _cleanupOldNotifications(cls): """ Delete all notifications older than a date determined by subtracting the number of days held in the value of the NOTIFICATION_RETENTION_PERIOD module-level variable from the current UTC timestamp. """ cutoffDate = (datetime.utcnow() - timedelta(days=NOTIFICATION_RETENTION_PERIOD)) # Disable `No value passed for parameter 'dml' in function call # (no-value-for-parameter)` warnings # pylint: disable=E1120 cmd = (monitorDispatcherTable.delete().where( monitorDispatcherTable.c.timestamp < cutoffDate)) @monitorsdb.retryOnTransientErrors def _executeWithRetries(): monitorsdb.engineFactory().execute(cmd) _executeWithRetries()
def clearAllNotificationsInteractiveConsoleScriptEntryPoint(cls): """ Interactive utility for manually clearing out all notifications. Meant to be used as a console script entry point, defined in setup.py. User will be prompted with a stern warning to delete notifications, and required to enter "Yes-" followed by a random integer. """ engine = monitorsdb.engineFactory() expectedAnswer = "Yes-%s" % (random.randint(1, 30), ) answer = raw_input( "Attention! You are about to do something irreversible, and potentially" " dangerous.\n" "\n" "To back out immediately without making any changes, feel free to type " "anything but \"{}\" in the prompt below, and press return.\n" "\n" "Should you choose to continue, all notifications in the DATABASE \"{}\"" "will be PERMANENTLY DELETED.\n" "\n" "Are you sure you want to continue? ".format( expectedAnswer, engine)) if answer.strip() != expectedAnswer: print "Aborting - Wise choice, my friend. Bye." return # Disable `No value passed for parameter 'dml' in function call # (no-value-for-parameter)` warnings # pylint: disable=E1120 cmd = monitorDispatcherTable.delete() @monitorsdb.retryOnTransientErrors def _executeWithRetries(): monitorsdb.engineFactory().execute(cmd) _executeWithRetries() print "Notifications deleted."
def clearAllNotificationsInteractiveConsoleScriptEntryPoint(cls): """ Interactive utility for manually clearing out all notifications. Meant to be used as a console script entry point, defined in setup.py. User will be prompted with a stern warning to delete notifications, and required to enter "Yes-" followed by a random integer. """ engine = monitorsdb.engineFactory() expectedAnswer = "Yes-%s" % (random.randint(1, 30),) answer = raw_input( "Attention! You are about to do something irreversible, and potentially" " dangerous.\n" "\n" "To back out immediately without making any changes, feel free to type " "anything but \"{}\" in the prompt below, and press return.\n" "\n" "Should you choose to continue, all notifications in the DATABASE \"{}\"" "will be PERMANENTLY DELETED.\n" "\n" "Are you sure you want to continue? " .format(expectedAnswer, engine)) if answer.strip() != expectedAnswer: print "Aborting - Wise choice, my friend. Bye." return # Disable `No value passed for parameter 'dml' in function call # (no-value-for-parameter)` warnings # pylint: disable=E1120 cmd = monitorDispatcherTable.delete() @monitorsdb.retryOnTransientErrors def _executeWithRetries(): monitorsdb.engineFactory().execute(cmd) _executeWithRetries() print "Notifications deleted."