Hi Prefect Team - Is there a way to pass the prefe...
# ask-community
c
Hi Prefect Team - Is there a way to pass the prefect logger to another class that is just using import logging? Our company was recently acquired and we need the new company to whitelist prefect. Hence, this issue is occurring during testing.
Copy code
from prefect import flow
from prefect.blocks.notifications import SlackWebhook
from prefect.logging import loggers
from src.services.delete_risk_scenario import delete_dbriskscenario_data_older_than_two_weeks
from prefect.blocks.system import String


@flow(name="Delete data older than two weeks in dbriskscenario tables")
def delete_data_older_than_two_weeks_dbriskscenario_tables(stored_procedures):
    logging = loggers.get_run_logger()
    slack_webhook_block = SlackWebhook.load("sra-slack-webhook")
    try:
        sra_db = String.load("sra-database").value
        results = delete_dbriskscenario_data_older_than_two_weeks(stored_procedures, sra_db, logging)
        <http://logging.info|logging.info>("Successfully deleted old data from dbriskscenario tables")
        <http://logging.info|logging.info>(results)
    except Exception as e:
        logging.error(f'Deleting dbriskscenario tables older than two weeks failed. {e}')
        slack_webhook_block.notify(f'Deleting dbriskscenario tables older than two weeks failed.')
Copy code
from src.utils.sradbService import execute_dbriskscenario_stored_procedures
from src.utils.connection import get_database_connection
import logging


def read_stored_procedure_input(stored_procedures_to_call):
    stored_procedures_names = [stored_procedures for db in stored_procedures_to_call.values() for stored_procedures in
                               db]
    return stored_procedures_names


def delete_dbriskscenario_data_older_than_two_weeks(
        stored_procedures, sra_db: str, logger: logging.Logger,
        get_db_connection_func=get_database_connection,
        execute_procedures_func=execute_dbriskscenario_stored_procedures):
    try:
        <http://logger.info|logger.info>('Test from delete_dbriskscenario_data_older_than_two_weeks')
        dbConnection = get_db_connection_func(secret_name=sra_db, logger=logger)
        stored_procedure_names = read_stored_procedure_input(stored_procedures)
        db = list(stored_procedures.keys())[0]
        results = execute_procedures_func(dbConnection=dbConnection, stored_procedure_names=stored_procedure_names, db=db, logger=logger)
        return results
    except Exception as e:
        raise