diff --git a/src/elab_orchestrator.py b/src/elab_orchestrator.py index fa36b1a..a99c889 100755 --- a/src/elab_orchestrator.py +++ b/src/elab_orchestrator.py @@ -45,7 +45,7 @@ async def worker(worker_id: int, cfg: object, pool: object) -> None: if record: id, unit_type, tool_type, unit_name, tool_name = [x.lower().replace(" ", "_") if isinstance(x, str) else x for x in record] if tool_type.lower() != "gd": # i tool GD non devono essere elaborati - tool_elab_info = await get_tool_info(WorkflowFlags.DATA_ELABORATED, tool_name.upper(), unit_name.upper(), pool) + tool_elab_info = await get_tool_info(WorkflowFlags.DATA_ELABORATED, unit_name.upper(), tool_name.upper(), pool) if tool_elab_info: if tool_elab_info['statustools'].lower() in cfg.elab_status: logger.info(f"Elaborazione id {id} per {unit_name} {tool_name} ") diff --git a/src/send_orchestrator.py b/src/send_orchestrator.py index 3251d15..7ccfcd2 100755 --- a/src/send_orchestrator.py +++ b/src/send_orchestrator.py @@ -42,7 +42,7 @@ async def worker(worker_id: int, cfg: object, pool: object) -> None: if record: id, unit_type, tool_type, unit_name, tool_name = [x.lower().replace(" ", "_") if isinstance(x, str) else x for x in record] - tool_elab_info = await get_tool_info(fase, unit_name, tool_name, pool) + tool_elab_info = await get_tool_info(fase, unit_name.upper(), tool_name.upper(), pool) if fase == WorkflowFlags.SENT_ELAB_DATA and tool_elab_info['ftp_send']: timestamp_matlab_elab = get_elab_timestamp(id, pool) if not tool_elab_info["duedate"] or tool_elab_info["duedate"] in ('0000-00-00 00:00:00', '') or tool_elab_info["duedate"] > timestamp_matlab_elab: diff --git a/src/utils/database/__init__.py b/src/utils/database/__init__.py index 73e813c..b696a1b 100644 --- a/src/utils/database/__init__.py +++ b/src/utils/database/__init__.py @@ -1,11 +1,11 @@ class WorkflowFlags: CSV_RECEIVED = 0 # 0000 DATA_LOADED = 1 # 0001 - DATA_ELABORATED = 2 # 0010 - SENT_RAW_DATA = 4 # 0100 - SENT_ELAB_DATA = 8 # 1000 - DUMMY_ELABORATED = 16 # 10000 - START_ELAB = 32 # 100000 + START_ELAB = 2 # 0010 + DATA_ELABORATED = 4 # 0100 + SENT_RAW_DATA = 8 # 1000 + SENT_ELAB_DATA = 16 # 10000 + DUMMY_ELABORATED = 32 # 100000 # Mappatura flag -> colonna timestamp FLAG_TO_TIMESTAMP = { diff --git a/src/utils/database/action_query.py b/src/utils/database/action_query.py index 2fce348..c4d1cd8 100644 --- a/src/utils/database/action_query.py +++ b/src/utils/database/action_query.py @@ -42,24 +42,28 @@ async def get_tool_info(next_status: int, unit: str, tool: str, pool: object) -> tuple: A dictionary-like object (aiomysql.DictCursor result) containing the tool information, or None if no information is found for the given unit and tool. """ + async with pool.acquire() as conn: async with conn.cursor(aiomysql.DictCursor) as cur: - await cur.execute(f""" - SELECT {sub_select[next_status]} - FROM matfuncs AS m - INNER JOIN tools AS t ON t.matfunc = m.id - INNER JOIN units AS u ON u.id = t.unit_id - INNER JOIN statustools AS s ON t.statustool_id = s.id - WHERE t.name = '{tool}' AND u.name = '{unit}'; - """) + try: + await cur.execute(f""" + SELECT {sub_select[next_status]} + FROM matfuncs AS m + INNER JOIN tools AS t ON t.matfunc = m.id + INNER JOIN units AS u ON u.id = t.unit_id + INNER JOIN statustools AS s ON t.statustool_id = s.id + WHERE t.name = '{tool}' AND u.name = '{unit}'; + """) - result = await cur.fetchone() + result = await cur.fetchone() - if not result: - logger.error(f"{unit} - {tool}: Tool info not found.") - return None - else: - return result + if not result: + logger.error(f"{unit} - {tool}: Tool info not found.") + return None + else: + return result + except Exception as e: + logger.error(f"Error: {e}") async def get_data_as_csv(cfg: dict, id_recv: int, unit: str, tool: str, matlab_timestamp: float, pool: object) -> str: