Пример #1
0
def connectivity():
    """Check connectivity to the database.

    Args:
        None

    Returns:
        valid: True if connectivity is OK

    """
    # Initialize key variables
    valid = False

    # Do test
    database = Database()
    session = database.session()

    try:
        session.query("1").from_statement(text("SELECT 1")).all()
        valid = True
    except Exception as ex:
        log.log2debug(1088, "connectivity() test failed because {}".format(ex))

    database.close()

    # Return
    return valid
Пример #2
0
    def checkout(dbapi_connection, connection_record, connection_proxy):
        """Checkout sub-processes connection for sub-processing if needed.

            Checkout is called when a connection is retrieved from the Pool.

        Args:
            dbapi_connection: Connection object
            connection_record: Connection record object
            connection_proxy: Connection proxy object

        Returns:
            None

        """
        # Get PID of main process
        pid = os.getpid()

        # Detect if this is a sub-process
        if connection_record.info['pid'] != pid:
            # substitute log.debug() or similar here as desired
            log_message = ('Parent process %s forked (%s) with an open '
                           'database connection, '
                           'which is being discarded and recreated.'
                           '') % (connection_record.info['pid'], pid)
            log.log2debug(1079, log_message)

            connection_record.connection = connection_proxy.connection = None
            raise exc.DisconnectionError(
                "Connection record belongs to pid %s, "
                "attempting to check out in pid %s" %
                (connection_record.info['pid'], pid))
Пример #3
0
    def purge(self):
        """Purge cache file that was read.

        Args:
            None

        Returns:
            success: "True" if successful

        """
        # Initialize key variables
        success = True

        try:
            os.remove(self.filename)
        except:
            success = False

        # Report success
        if success is True:
            log_message = ('Ingest cache file %s deleted') % (self.filename)
            log.log2debug(1046, log_message)
        else:
            log_message = ('Failed to delete ingest cache file %s') % (
                self.filename)
            log.log2debug(1087, log_message)

        # Return
        return success
Пример #4
0
    def valid(self):
        """Master method that defines whether data is OK.

        Args:
            None

        Returns:
            all_ok:

        """
        # Initialize key variables
        valid_list = [self._valid]
        ts_start = time.time()

        # Check timeseries and timefixed data in the data
        if len(valid_list) == valid_list.count(True):
            check = _CheckData(self.information)
            valid_list.append(check.valid())

        # Check if data to be validated is already in the database
        if len(valid_list) == valid_list.count(True):
            check = _CheckDuplicates(self.information)
            valid_list.append(check.valid())

        # Do final check
        if len(valid_list) == valid_list.count(True):
            # Log success
            ts_stop = time.time()
            duration = ts_stop - ts_start
            log_message = (
                'Data validation of %s took %s seconds.'
                '') % (self.filepath, round(duration, 4))
            log.log2debug(1126, log_message)
            all_ok = True

        else:
            # Log failure
            log_message = ('Cache data in %s is invalid') % (self.filepath)
            log.log2warning(1059, log_message)
            all_ok = False

        # Return
        return all_ok