util ftp renamed connect
This commit is contained in:
2
env/send.ini
vendored
2
env/send.ini
vendored
@@ -2,4 +2,4 @@
|
|||||||
logFilename = ../logs/send_data.log
|
logFilename = ../logs/send_data.log
|
||||||
|
|
||||||
[threads]
|
[threads]
|
||||||
max_num = 5
|
max_num = 30
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
from utils.config import loader_ftp_csv as setting
|
from utils.config import loader_ftp_csv as setting
|
||||||
from utils.database.connection import connetti_db
|
from utils.database.connection import connetti_db
|
||||||
from utils.ftp import user_admin, file_management
|
from utils.connect import user_admin, file_management
|
||||||
|
|
||||||
from pyftpdlib.handlers import FTPHandler
|
from pyftpdlib.handlers import FTPHandler
|
||||||
from pyftpdlib.servers import FTPServer
|
from pyftpdlib.servers import FTPServer
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from utils.config import loader_send_data as setting
|
|||||||
from utils.database import WorkflowFlags
|
from utils.database import WorkflowFlags
|
||||||
from utils.csv.loaders import get_next_csv_atomic
|
from utils.csv.loaders import get_next_csv_atomic
|
||||||
from utils.orchestrator_utils import run_orchestrator, worker_context
|
from utils.orchestrator_utils import run_orchestrator, worker_context
|
||||||
from utils.database.action_query import process_workflow_record
|
from utils.connect.send_data import process_workflow_record
|
||||||
from utils.general import alterna_valori
|
from utils.general import alterna_valori
|
||||||
#from utils.ftp.send_data import ftp_send_elab_csv_to_customer, api_send_elab_csv_to_customer, ftp_send_raw_csv_to_customer, api_send_raw_csv_to_customer
|
#from utils.ftp.send_data import ftp_send_elab_csv_to_customer, api_send_elab_csv_to_customer, ftp_send_raw_csv_to_customer, api_send_raw_csv_to_customer
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from ftplib import FTP, FTP_TLS, all_errors
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import logging
|
import logging
|
||||||
import aiomysql
|
import aiomysql
|
||||||
import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from utils.database.loader_action import update_status, unlock
|
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
|
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()
|
send_ftp_info = await cur.fetchone()
|
||||||
logger.info(f"id {id} - {unit} - {tool}: estratti i dati per invio via ftp")
|
logger.info(f"id {id} - {unit} - {tool}: estratti i dati per invio via ftp")
|
||||||
except Exception as e:
|
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:
|
try:
|
||||||
# Converti in bytes
|
# Converti in bytes
|
||||||
@@ -166,19 +166,24 @@ async def process_workflow_record(record: tuple, fase: int, cfg: dict, pool: obj
|
|||||||
try:
|
try:
|
||||||
# Recupero informazioni principali
|
# Recupero informazioni principali
|
||||||
tool_elab_info = await get_tool_info(fase, unit_name.upper(), tool_name.upper(), pool)
|
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
|
# Verifica se il processing può essere eseguito
|
||||||
if not _should_process(tool_elab_info, timestamp_matlab_elab):
|
if not _should_process(tool_elab_info, timestamp_matlab_elab):
|
||||||
logger.info(f"id {id} - {unit_name} - {tool_name} {tool_elab_info['duedate']}: "
|
logger.info(f"id {id} - {unit_name} - {tool_name} {tool_elab_info['duedate']}: "
|
||||||
"elaborazione saltata - due date raggiunta.")
|
"invio dati non eseguito - due date raggiunta.")
|
||||||
return
|
|
||||||
|
|
||||||
# Routing basato sulla fase
|
await update_status(cfg, id, fase, pool)
|
||||||
success = await _route_by_phase(fase, tool_elab_info, cfg, id, unit_name, tool_name,
|
return
|
||||||
timestamp_matlab_elab, pool)
|
|
||||||
|
|
||||||
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)
|
await update_status(cfg, id, fase, pool)
|
||||||
|
|
||||||
except Exception as e:
|
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)
|
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."""
|
"""Verifica se il record può essere processato basandosi sulla due date."""
|
||||||
duedate = tool_elab_info.get("duedate")
|
duedate = tool_elab_info.get("duedate")
|
||||||
|
|
||||||
@@ -201,6 +206,29 @@ def _should_process(tool_elab_info, timestamp_matlab_elab):
|
|||||||
return duedate > comparison_timestamp
|
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,
|
async def _route_by_phase(fase, tool_elab_info, cfg, id, unit_name, tool_name,
|
||||||
timestamp_matlab_elab, pool):
|
timestamp_matlab_elab, pool):
|
||||||
"""
|
"""
|
||||||
@@ -58,7 +58,7 @@ async def get_tool_info(next_status: int, unit: str, tool: str, pool: object) ->
|
|||||||
result = await cur.fetchone()
|
result = await cur.fetchone()
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
logger.error(f"{unit} - {tool}: Tool info not found.")
|
logger.warning(f"{unit} - {tool}: Tool info not found.")
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user