(db, redis)
Move the metrics values from redis to the DB.

    Get all the redis keys with the metrics prefix,
    parse the key to get the timestamp in the key.
    If it is before the current time, then process the redis hset.
Move the metrics values from redis to the DB.
Move the metrics values from redis to the DB .
def sweep_metrics(db, redis):
    """
    Move the metrics values from redis to the DB.

    Get all the redis keys with the metrics prefix,
    parse the key to get the timestamp in the key.
    If it is before the current time, then process the redis hset.
    """
    with db.scoped_session() as session:
        for key_byte in redis.scan_iter(f"{metrics_prefix}:*"):
            key = key_byte.decode("utf-8")
            try:
                parsed_key = parse_metrics_key(key)

                if parsed_key is None:
                    raise KeyError(
                        f"index_metrics.py | Unable to parse key {key} | Skipping process key"
                    )
                source, ip, key_date = parsed_key

                current_date_time = get_rounded_date_time()

                if key_date < current_date_time:
                    if source == metrics_routes:
                        process_route_keys(session, redis, key, ip, key_date)
                    elif source == metrics_applications:
                        process_app_name_keys(session, redis, key, ip, key_date)
            except KeyError as e:
                logger.warning(e)
                redis.delete(key)
            except Exception as e:
                logger.error(e)
                redis.delete(key)
def sweep_metrics ( db , redis ) : with db . scoped_session ( ) as session : for key_byte in redis . scan_iter ( f"{metrics_prefix}:*" ) : key = key_byte . decode ( "utf-8" ) try : parsed_key = parse_metrics_key ( key ) if parsed_key is None : raise KeyError ( f"index_metrics.py | Unable to parse key {key} | Skipping process key" ) source , ip , key_date = parsed_key current_date_time = get_rounded_date_time ( ) if key_date < current_date_time : if source == metrics_routes : process_route_keys ( session , redis , key , ip , key_date ) elif source == metrics_applications : process_app_name_keys ( session , redis , key , ip , key_date ) except KeyError as e : logger . warning ( e ) redis . delete ( key ) except Exception as e : logger . error ( e ) redis . delete ( key )