Skip to content

rs_workflows/operation/init_quota_monitoring_flow.md

<< Back to index

Create the Prefect flow to setup the quota monitoring database

create_schema(db_url)

Creates all database tables defined in the quota_moniotirng_db_models.

This task initializes the database schema for the Quota Monitoring database using the provided SQLAlchemy engine.

Parameters:

Name Type Description Default
engine Engine

SQLAlchemy database engine connected to the target database.

required
Source code in docs/rs-client-libraries/rs_workflows/operation/init_quota_monitoring_flow.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@task
def create_schema(db_url: str):
    """
    Creates all database tables defined in the quota_moniotirng_db_models.

    This task initializes the database schema for the Quota Monitoring database
    using the provided SQLAlchemy engine.

    Args:
        engine (sqlalchemy.engine.Engine): SQLAlchemy database engine connected to the target database.
    """
    logger = get_run_logger()
    engine = create_engine(db_url)
    logger.info("Call the engine to create the table for quota monitoring")
    Base.metadata.create_all(engine)

init_quota_monitoring_database(env=FlowEnvArgs(owner_id='operator-quota')) async

Initializes the Quota Monitoring database schema.

This Prefect flow
  • Creates all required tables for the Quota Monitoring database.

Parameters:

Name Type Description Default
env FlowEnvArgs

Prefect flow environment configuration, including runtime context variables.

FlowEnvArgs(owner_id='operator-quota')
Environment Variables Required

POSTGRES_QUOTA_USER: PostgreSQL username for quota database POSTGRES_QUOTA_PASSWORD: PostgreSQL password POSTGRES_HOST (str): PostgreSQL host address. POSTGRES_PORT (str): PostgreSQL port.

Source code in docs/rs-client-libraries/rs_workflows/operation/init_quota_monitoring_flow.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
@flow(name="quota-monitoring-db-create")
async def init_quota_monitoring_database(env: FlowEnvArgs = FlowEnvArgs(owner_id="operator-quota")):
    """
    Initializes the Quota Monitoring database schema.

    This Prefect flow:
      - Creates all required tables for the Quota Monitoring database.

    Args:
        env (FlowEnvArgs): Prefect flow environment configuration, including runtime context variables.

    Environment Variables Required:
        POSTGRES_QUOTA_USER: PostgreSQL username for quota database
        POSTGRES_QUOTA_PASSWORD: PostgreSQL password
        POSTGRES_HOST (str): PostgreSQL host address.
        POSTGRES_PORT (str): PostgreSQL port.

    """
    logger = get_run_logger()

    # Init flow environment and opentelemetry span
    flow_env = FlowEnv(env)
    with flow_env.start_span(__name__, "init-quota-monitoring-database"):
        password = quote_plus(os.environ["POSTGRES_QUOTA_PASSWORD"])

        db_url = (
            f"postgresql+psycopg2://{os.environ['POSTGRES_QUOTA_USER']}:"
            f"{password}@{os.environ['POSTGRES_HOST']}:"
            f"{os.environ['POSTGRES_PORT']}/" + DB_NAME
        )
        create_schema(db_url)  # type: ignore[unused-coroutine]

        logger.info("The initialization of the tables for the Quota Monitoring database finished")