Commit ffe46d58 authored by Jay's avatar Jay
Browse files

Streamlines connections to the DB

parent 6ef538d5
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -215,7 +215,7 @@ def main(): # pragma: no cover
    logging.basicConfig(level=os.environ.get("AUTOCNET_LOGLEVEL", "INFO"))
    logging.basicConfig(level=os.environ.get("AUTOCNET_LOGLEVEL", "INFO"))
    # Get the message
    # Get the message
    queue = StrictRedis(host=args['host'], port=args['port'], db=0,
    queue = StrictRedis(host=args['host'], port=args['port'], db=0,
                        socket_timeout=30, socket_connect_timeout=300)
                        socket_timeout=30, socket_connect_timeout=30)
    manage_messages(args, queue)
    manage_messages(args, queue)


if __name__ == '__main__':
if __name__ == '__main__':
+1 −1
Original line number Original line Diff line number Diff line
@@ -2418,7 +2418,7 @@ class NetworkCandidateGraph(CandidateGraph):
        >>> ncg.add_from_remote_database(source_db_config, outpath, query_string=query)
        >>> ncg.add_from_remote_database(source_db_config, outpath, query_string=query)
        """
        """


        sourceSession, _ = new_connection(source_db_config)
        sourceSession, _ = new_connection(source_db_config, with_session=True)
        sourcesession = sourceSession()
        sourcesession = sourceSession()


        sourceimages = sourcesession.execute(query_string).fetchall()
        sourceimages = sourcesession.execute(query_string).fetchall()
+9 −6
Original line number Original line Diff line number Diff line
@@ -29,8 +29,8 @@ def retry(max_retries=5, wait_time=300):
        return wrapper
        return wrapper
    return decorator
    return decorator


@retry
@retry()
def new_connection(dbconfig):
def new_connection(dbconfig, with_session=False):
    """
    """
    Using the user supplied config create a NullPool database connection.
    Using the user supplied config create a NullPool database connection.


@@ -40,6 +40,8 @@ def new_connection(dbconfig):
               Dictionary defining necessary parameters for the database
               Dictionary defining necessary parameters for the database
               connection
               connection


    with_session : boolean
                   If true return a SQL Alchemy session factory. Default False.
    Returns
    Returns
    -------
    -------
    Session : object
    Session : object
@@ -57,8 +59,9 @@ def new_connection(dbconfig):
    engine = create_engine(db_uri,
    engine = create_engine(db_uri,
                poolclass=pool.NullPool,
                poolclass=pool.NullPool,
                connect_args={"application_name":f"AutoCNet_{hostname}"},
                connect_args={"application_name":f"AutoCNet_{hostname}"},
                isolation_level="AUTOCOMMIT",
                pool_pre_ping=True)
                pool_pre_ping=True)
    if with_session:
        Session = orm.sessionmaker(bind=engine, autocommit=False)
        Session = orm.sessionmaker(bind=engine, autocommit=False)
        log.debug(Session, engine)
        log.debug(Session, engine)
        return Session, engine
        return Session, engine
    return engine
+3 −1
Original line number Original line Diff line number Diff line
@@ -1156,7 +1156,9 @@ def validate_candidate_measure(point,
    sample = measure_to_register['sample']
    sample = measure_to_register['sample']
    line = measure_to_register['line']
    line = measure_to_register['line']


    log.info(f'Validating measure: {measure_to_register['id']} on image: {source_imageid}')
    mid = measure_to_register['id']
    sid = measure_to_register['imageid']
    log.info(f'Validating measure: {mid} on image: {sid}')


    reference_roi = roi.Roi(source_node.geodata, 
    reference_roi = roi.Roi(source_node.geodata, 
                            sample, 
                            sample, 
+2 −2
Original line number Original line Diff line number Diff line
@@ -228,7 +228,7 @@ def place_points_in_overlap(overlap,
    log.info(f'Have {len(candidate_points)} potential points to place in overlap {overlap.id}.')
    log.info(f'Have {len(candidate_points)} potential points to place in overlap {overlap.id}.')
    
    
    nodes = get_nodes_for_overlap(ncg, session, overlap)
    nodes = get_nodes_for_overlap(ncg, session, overlap)

    logging.debug(f'Nodes: {nodes}')
    points_to_commit = []
    points_to_commit = []
    for valid in candidate_points:
    for valid in candidate_points:
        log.debug(f'Valid point: {valid}')
        log.debug(f'Valid point: {valid}')