fix x channels
This commit is contained in:
@@ -39,7 +39,7 @@ async def worker(worker_id: int, queue: asyncio.Queue, cfg: object) -> None:
|
||||
|
||||
logger.info(f"Worker {worker_id} - Inizio elaborazione")
|
||||
|
||||
record, success = await load_csv(cfg)
|
||||
record, success = await load_csv(cfg, worker_id)
|
||||
|
||||
if not record:
|
||||
logger.debug(f"Worker {worker_id} - Nessun record trovato")
|
||||
@@ -58,7 +58,7 @@ async def worker(worker_id: int, queue: asyncio.Queue, cfg: object) -> None:
|
||||
queue.task_done()
|
||||
|
||||
|
||||
async def load_csv(cfg: object) -> tuple:
|
||||
async def load_csv(cfg: object, worker_id: int) -> tuple:
|
||||
"""
|
||||
Cerca e carica un file CSV da elaborare dal database.
|
||||
|
||||
@@ -70,12 +70,12 @@ async def load_csv(cfg: object) -> tuple:
|
||||
"""
|
||||
|
||||
debug_mode = (logging.getLogger().getEffectiveLevel() == logging.DEBUG)
|
||||
logger.debug("Inizio ricerca nuovo CSV da elaborare")
|
||||
logger.debug(f"Worker {worker_id} - Inizio ricerca nuovo CSV da elaborare")
|
||||
|
||||
try:
|
||||
with connetti_db(cfg) as conn:
|
||||
cur = conn.cursor()
|
||||
logger.debug("Connessione al database stabilita")
|
||||
logger.debug(f"Worker {worker_id} - Connessione al database stabilita")
|
||||
|
||||
query = f"""
|
||||
SELECT id, unit_type, tool_type, unit_name, tool_name
|
||||
@@ -83,16 +83,16 @@ async def load_csv(cfg: object) -> tuple:
|
||||
WHERE locked = 0 AND status = {CSV_RECEIVED}
|
||||
LIMIT 1
|
||||
"""
|
||||
logger.debug(f"Esecuzione query: {query}")
|
||||
logger.debug(f"Worker {worker_id} - Esecuzione query: {query}")
|
||||
cur.execute(query)
|
||||
result = cur.fetchone()
|
||||
|
||||
if result:
|
||||
id, unit_type, tool_type, unit_name, tool_name = result
|
||||
logger.info(f"Trovato CSV da elaborare: ID={id}, Tipo={unit_type}_{tool_type}, Nome={unit_name}_{tool_name}")
|
||||
logger.info(f"Worker {worker_id} - Trovato CSV da elaborare: ID={id}, Tipo={unit_type}_{tool_type}, Nome={unit_name}_{tool_name}")
|
||||
|
||||
lock_query = f"UPDATE {cfg.dbname}.{cfg.dbrectable} SET locked = 1 WHERE id = {id}"
|
||||
logger.debug(f"Lock del record: {lock_query}")
|
||||
logger.debug(f"Worker {worker_id} - Esecuzione lock del record: {lock_query}")
|
||||
cur.execute(lock_query)
|
||||
conn.commit()
|
||||
|
||||
@@ -104,14 +104,14 @@ async def load_csv(cfg: object) -> tuple:
|
||||
modulo = None
|
||||
for module_name in module_names:
|
||||
try:
|
||||
logger.debug(f"Caricamento dinamico del modulo: {module_name}")
|
||||
logger.debug(f"Worker {worker_id} - Caricamento dinamico del modulo: {module_name}")
|
||||
modulo = importlib.import_module(module_name)
|
||||
logger.debug(f"Funzione 'main_loader' caricata dal modulo {module_name}")
|
||||
logger.debug(f"Worker {worker_id} - Funzione 'main_loader' caricata dal modulo {module_name}")
|
||||
except (ImportError, AttributeError) as e:
|
||||
logger.warning(f"Modulo {module_name} non trovato: {e}", exc_info=debug_mode)
|
||||
logger.info(f"Worker {worker_id} - Modulo {module_name} non presente o non valido. {e}", exc_info=debug_mode)
|
||||
|
||||
if not modulo:
|
||||
logger.error(f"Nessun modulo trovato {module_names}")
|
||||
logger.error(f"Worker {worker_id} - Nessun modulo trovato {module_names}")
|
||||
return True, False
|
||||
|
||||
# Ottiene la funzione 'main_loader' dal modulo
|
||||
@@ -120,14 +120,14 @@ async def load_csv(cfg: object) -> tuple:
|
||||
|
||||
# Esegui la funzione
|
||||
await funzione(cfg, id)
|
||||
logger.info(f"Elaborazione completata per ID={id}")
|
||||
logger.info(f"Worker {worker_id} - Elaborazione completata per ID={id}")
|
||||
return True, True
|
||||
else:
|
||||
logger.debug("Nessun record disponibile per l'elaborazione")
|
||||
logger.debug(f"Worker {worker_id} - Nessun record disponibile per l'elaborazione")
|
||||
return False, False
|
||||
|
||||
except mysql.connector.Error as e:
|
||||
logger.error(f"Errore di database: {e}", exc_info=debug_mode)
|
||||
logger.error(f"Worker {worker_id} - Errore database: {e}", exc_info=debug_mode)
|
||||
return False, False
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user