fix flag elab
This commit is contained in:
@@ -12,7 +12,6 @@ import asyncio
|
||||
from utils.config import loader_load_data as setting
|
||||
from utils.database import WorkflowFlags
|
||||
from utils.csv.loaders import get_next_csv_atomic
|
||||
from utils.database.action_query import check_flag_elab
|
||||
from utils.orchestrator_utils import run_orchestrator, worker_context
|
||||
|
||||
# Initialize the logger for this module
|
||||
@@ -24,7 +23,7 @@ CSV_PROCESSING_DELAY = 0.2
|
||||
NO_RECORD_SLEEP = 60
|
||||
|
||||
|
||||
async def worker(worker_id: int, cfg: object, pool: object) -> None:
|
||||
async def worker(worker_id: int, cfg: dict, pool: object) -> None:
|
||||
"""Esegue il ciclo di lavoro per l'elaborazione dei file CSV.
|
||||
|
||||
Il worker preleva un record CSV dal database, ne elabora il contenuto
|
||||
@@ -32,7 +31,7 @@ async def worker(worker_id: int, cfg: object, pool: object) -> None:
|
||||
|
||||
Args:
|
||||
worker_id (int): L'ID univoco del worker.
|
||||
cfg (object): L'oggetto di configurazione.
|
||||
cfg (dict): L'oggetto di configurazione.
|
||||
pool (object): Il pool di connessioni al database.
|
||||
"""
|
||||
# Imposta il context per questo worker
|
||||
@@ -43,24 +42,20 @@ async def worker(worker_id: int, cfg: object, pool: object) -> None:
|
||||
while True:
|
||||
try:
|
||||
logger.info("Inizio elaborazione")
|
||||
if not await check_flag_elab():
|
||||
record = await get_next_csv_atomic(
|
||||
pool,
|
||||
cfg.dbrectable,
|
||||
WorkflowFlags.CSV_RECEIVED,
|
||||
WorkflowFlags.DATA_LOADED,
|
||||
)
|
||||
record = await get_next_csv_atomic(
|
||||
pool,
|
||||
cfg.dbrectable,
|
||||
WorkflowFlags.CSV_RECEIVED,
|
||||
WorkflowFlags.DATA_LOADED,
|
||||
)
|
||||
|
||||
if record:
|
||||
success = await load_csv(record, cfg, pool)
|
||||
if not success:
|
||||
logger.error("Errore durante l'elaborazione")
|
||||
await asyncio.sleep(CSV_PROCESSING_DELAY)
|
||||
else:
|
||||
logger.info("Nessun record disponibile")
|
||||
await asyncio.sleep(NO_RECORD_SLEEP)
|
||||
if record:
|
||||
success = await load_csv(record, cfg, pool)
|
||||
if not success:
|
||||
logger.error("Errore durante l'elaborazione")
|
||||
await asyncio.sleep(CSV_PROCESSING_DELAY)
|
||||
else:
|
||||
logger.info("Flag fermo elaborazione attivato")
|
||||
logger.info("Nessun record disponibile")
|
||||
await asyncio.sleep(NO_RECORD_SLEEP)
|
||||
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
|
||||
Reference in New Issue
Block a user