generated from dopt-python/py311
internalised connection to database and added main routine
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from typing import Final
|
from typing import TYPE_CHECKING, Final
|
||||||
|
|
||||||
import dopt_basics.datetime as dopt_dt
|
import dopt_basics.datetime as dopt_dt
|
||||||
import oracledb
|
import oracledb
|
||||||
@@ -11,28 +13,13 @@ from wattanalyse import db, pipelines
|
|||||||
from wattanalyse.constants import USER_CFG
|
from wattanalyse.constants import USER_CFG
|
||||||
from wattanalyse.logging import logger_base, logger_database, logger_pipeline
|
from wattanalyse.logging import logger_base, logger_database, logger_pipeline
|
||||||
|
|
||||||
try:
|
if TYPE_CHECKING:
|
||||||
ORACLE_CONN = oracledb.connect(
|
from wattanalyse.pipelines import OracleConnection
|
||||||
user=USER_CFG.Datenbank.Nutzer,
|
|
||||||
password=USER_CFG.Datenbank.Passwort,
|
|
||||||
host=USER_CFG.Datenbank.Host,
|
|
||||||
port=USER_CFG.Datenbank.Port,
|
|
||||||
service_name=USER_CFG.Datenbank.Service_Name,
|
|
||||||
)
|
|
||||||
except OperationalError as err:
|
|
||||||
logger_base.error(
|
|
||||||
(
|
|
||||||
"[Oracle Database] Could not establish connection. Check if the database "
|
|
||||||
"online, fully functional and reachable. Check the configuration parameters.\n"
|
|
||||||
">>> Exception:\n%s"
|
|
||||||
),
|
|
||||||
err,
|
|
||||||
stack_info=True,
|
|
||||||
)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def pipeline_KPI_calculation() -> int:
|
def pipeline_KPI_calculation(
|
||||||
|
conn: OracleConnection,
|
||||||
|
) -> int:
|
||||||
return_code: int = 0
|
return_code: int = 0
|
||||||
PIPELINE_NAME: Final[str] = "KPI_calculation"
|
PIPELINE_NAME: Final[str] = "KPI_calculation"
|
||||||
logger_pipeline.info("Start pipeline >%s<", PIPELINE_NAME)
|
logger_pipeline.info("Start pipeline >%s<", PIPELINE_NAME)
|
||||||
@@ -40,7 +27,7 @@ def pipeline_KPI_calculation() -> int:
|
|||||||
start = dopt_dt.current_time_tz()
|
start = dopt_dt.current_time_tz()
|
||||||
t1 = time.perf_counter_ns()
|
t1 = time.perf_counter_ns()
|
||||||
|
|
||||||
res_pipe = pipelines.KPI_calculation(ORACLE_CONN)
|
res_pipe = pipelines.KPI_calculation(conn)
|
||||||
|
|
||||||
t2 = time.perf_counter_ns()
|
t2 = time.perf_counter_ns()
|
||||||
|
|
||||||
@@ -89,14 +76,34 @@ def pipeline_KPI_calculation() -> int:
|
|||||||
return return_code
|
return return_code
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main() -> None:
|
||||||
try:
|
try:
|
||||||
code = pipeline_KPI_calculation()
|
ORACLE_CONN = oracledb.connect(
|
||||||
|
user=USER_CFG.Datenbank.Nutzer,
|
||||||
|
password=USER_CFG.Datenbank.Passwort,
|
||||||
|
host=USER_CFG.Datenbank.Host,
|
||||||
|
port=USER_CFG.Datenbank.Port,
|
||||||
|
service_name=USER_CFG.Datenbank.Service_Name,
|
||||||
|
)
|
||||||
|
except OperationalError as err:
|
||||||
|
logger_base.critical(
|
||||||
|
(
|
||||||
|
"[Oracle Database] Could not establish connection. Check if the database "
|
||||||
|
"is online, fully functional and reachable. Check the configuration "
|
||||||
|
"parameters.\n>>> Exception:\n%s"
|
||||||
|
),
|
||||||
|
err,
|
||||||
|
stack_info=True,
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
code = pipeline_KPI_calculation(ORACLE_CONN)
|
||||||
sys.exit(code)
|
sys.exit(code)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger_base.error(
|
logger_base.critical(
|
||||||
(
|
(
|
||||||
"[BASE ERROR] An unexpected and unwrapped error occurred during the "
|
"[BASE] An unexpected and unwrapped error occurred during the "
|
||||||
"execution of the pipeline function.\n>>> Exception:\n%s"
|
"execution of the pipeline function.\n>>> Exception:\n%s"
|
||||||
),
|
),
|
||||||
err,
|
err,
|
||||||
@@ -105,3 +112,7 @@ if __name__ == "__main__":
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
finally:
|
finally:
|
||||||
ORACLE_CONN.close()
|
ORACLE_CONN.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user