|
|
|
|
@@ -2,7 +2,7 @@ from ftplib import FTP, FTP_TLS, all_errors
|
|
|
|
|
from io import BytesIO
|
|
|
|
|
import logging
|
|
|
|
|
import aiomysql
|
|
|
|
|
import datetime
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
from utils.database.loader_action import update_status, unlock
|
|
|
|
|
from utils.database.action_query import get_data_as_csv, get_tool_info, get_elab_timestamp
|
|
|
|
|
@@ -77,7 +77,7 @@ async def ftp_send_elab_csv_to_customer(cfg: dict, id: int, unit: str, tool: str
|
|
|
|
|
send_ftp_info = await cur.fetchone()
|
|
|
|
|
logger.info(f"id {id} - {unit} - {tool}: estratti i dati per invio via ftp")
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"id {id} - {unit} - {tool} - errore nel query per invio ftp: {e}")
|
|
|
|
|
logger.error(f"id {id} - {unit} - {tool} - errore nella query per invio ftp: {e}")
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# Converti in bytes
|
|
|
|
|
@@ -166,19 +166,24 @@ async def process_workflow_record(record: tuple, fase: int, cfg: dict, pool: obj
|
|
|
|
|
try:
|
|
|
|
|
# Recupero informazioni principali
|
|
|
|
|
tool_elab_info = await get_tool_info(fase, unit_name.upper(), tool_name.upper(), pool)
|
|
|
|
|
timestamp_matlab_elab = await get_elab_timestamp(id, pool)
|
|
|
|
|
if tool_elab_info:
|
|
|
|
|
timestamp_matlab_elab = await get_elab_timestamp(id, pool)
|
|
|
|
|
|
|
|
|
|
# Verifica se il processing può essere eseguito
|
|
|
|
|
if not _should_process(tool_elab_info, timestamp_matlab_elab):
|
|
|
|
|
logger.info(f"id {id} - {unit_name} - {tool_name} {tool_elab_info['duedate']}: "
|
|
|
|
|
"elaborazione saltata - due date raggiunta.")
|
|
|
|
|
return
|
|
|
|
|
# Verifica se il processing può essere eseguito
|
|
|
|
|
if not _should_process(tool_elab_info, timestamp_matlab_elab):
|
|
|
|
|
logger.info(f"id {id} - {unit_name} - {tool_name} {tool_elab_info['duedate']}: "
|
|
|
|
|
"invio dati non eseguito - due date raggiunta.")
|
|
|
|
|
|
|
|
|
|
# Routing basato sulla fase
|
|
|
|
|
success = await _route_by_phase(fase, tool_elab_info, cfg, id, unit_name, tool_name,
|
|
|
|
|
timestamp_matlab_elab, pool)
|
|
|
|
|
await update_status(cfg, id, fase, pool)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if success:
|
|
|
|
|
# Routing basato sulla fase
|
|
|
|
|
success = await _route_by_phase(fase, tool_elab_info, cfg, id, unit_name, tool_name,
|
|
|
|
|
timestamp_matlab_elab, pool)
|
|
|
|
|
|
|
|
|
|
if success:
|
|
|
|
|
await update_status(cfg, id, fase, pool)
|
|
|
|
|
else:
|
|
|
|
|
await update_status(cfg, id, fase, pool)
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
@@ -188,7 +193,7 @@ async def process_workflow_record(record: tuple, fase: int, cfg: dict, pool: obj
|
|
|
|
|
await unlock(cfg, id, pool)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _should_process(tool_elab_info, timestamp_matlab_elab):
|
|
|
|
|
def _should_process_old(tool_elab_info, timestamp_matlab_elab):
|
|
|
|
|
"""Verifica se il record può essere processato basandosi sulla due date."""
|
|
|
|
|
duedate = tool_elab_info.get("duedate")
|
|
|
|
|
|
|
|
|
|
@@ -201,6 +206,29 @@ def _should_process(tool_elab_info, timestamp_matlab_elab):
|
|
|
|
|
return duedate > comparison_timestamp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _should_process(tool_elab_info, timestamp_matlab_elab):
|
|
|
|
|
"""Verifica se il record può essere processato basandosi sulla due date."""
|
|
|
|
|
duedate = tool_elab_info.get("duedate")
|
|
|
|
|
|
|
|
|
|
# Se non c'è duedate o è vuota/nulla, può essere processato
|
|
|
|
|
if not duedate or duedate in ('0000-00-00 00:00:00', ''):
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
# Se timestamp_matlab_elab è None/null, usa il timestamp corrente
|
|
|
|
|
comparison_timestamp = timestamp_matlab_elab if timestamp_matlab_elab is not None else datetime.now()
|
|
|
|
|
|
|
|
|
|
# Converti duedate in datetime se è una stringa
|
|
|
|
|
if isinstance(duedate, str):
|
|
|
|
|
duedate = datetime.strptime(duedate, '%Y-%m-%d %H:%M:%S')
|
|
|
|
|
|
|
|
|
|
# Assicurati che comparison_timestamp sia datetime
|
|
|
|
|
if isinstance(comparison_timestamp, str):
|
|
|
|
|
comparison_timestamp = datetime.strptime(comparison_timestamp, '%Y-%m-%d %H:%M:%S')
|
|
|
|
|
|
|
|
|
|
return duedate > comparison_timestamp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def _route_by_phase(fase, tool_elab_info, cfg, id, unit_name, tool_name,
|
|
|
|
|
timestamp_matlab_elab, pool):
|
|
|
|
|
"""
|