def get_latest_snapshot_timestamp(self, statuses): """Select the latest timestamp of the completed snapshot. Args: statuses (tuple): The tuple of snapshot statuses to filter on. Returns: str: The string timestamp of the latest complete snapshot. Raises: MySQLError: When no rows are found. """ # Build a dynamic parameterized query string for filtering the # snapshot statuses if not isinstance(statuses, tuple): statuses = ('SUCCESS', ) status_params = ','.join(['%s'] * len(statuses)) filter_clause = SNAPSHOT_STATUS_FILTER_CLAUSE.format(status_params) try: cursor = self.conn.cursor() cursor.execute( select_data.LATEST_SNAPSHOT_TIMESTAMP + filter_clause, statuses) row = cursor.fetchone() if row: return row[0] raise NoResultsError('No snapshot cycle found.') except (DataError, IntegrityError, InternalError, NotSupportedError, OperationalError, ProgrammingError, NoResultsError) as e: raise MySQLError('snapshot_cycles', e)
def select_latest_complete_snapshot_timestamp(self, statuses): """Select the latest timestamp of the completed snapshot. Args: statuses: The tuple of snapshot statuses to filter on. Returns: The string timestamp of the latest complete snapshot. Raises: MySQLError (NoResultsError) if no rows are found. """ # Build a dynamic parameterized query string for filtering the # snapshot statuses if not statuses: statuses = ('SUCCESS') # TODO: Investigate improving to avoid the pylint disable. status_params = ','.join(['%s' for s in statuses]) # pylint: disable=unused-variable filter_clause = ' where status in ({})'.format(status_params) try: cursor = self.conn.cursor() cursor.execute( select_data.LATEST_SNAPSHOT_TIMESTAMP + filter_clause, statuses) rows = cursor.fetchall() if rows and rows[0]: return rows[0][0] raise NoResultsError('No snapshot cycle found.') except (DataError, IntegrityError, InternalError, NotSupportedError, OperationalError, ProgrammingError, NoResultsError) as e: raise MySQLError('snapshot_cycles', e)