fix logging to use the new
This commit is contained in:
@@ -56,5 +56,5 @@ async def get_data_as_csv(cfg: dict, id_recv: int, unit: str, tool: str, matlab_
|
||||
return csv_data
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"id {id_recv} - {unit} - {tool} - errore nel query creazione csv: {e}")
|
||||
logger.error(f"id {id_recv} - {unit} - {tool} - errore nel query creazione csv: {e}")
|
||||
return None
|
||||
@@ -68,7 +68,7 @@ async def load_data(cfg: object, matrice_valori: list, pool: object) -> bool:
|
||||
async with conn.cursor() as cur:
|
||||
for attempt in range(cfg.max_retries):
|
||||
try:
|
||||
logging.info(f"Loading data attempt {attempt + 1}.")
|
||||
logger.info(f"Loading data attempt {attempt + 1}.")
|
||||
|
||||
for i in range(0, len(matrice_valori), BATCH_SIZE):
|
||||
batch = matrice_valori[i:i + BATCH_SIZE]
|
||||
@@ -76,17 +76,18 @@ async def load_data(cfg: object, matrice_valori: list, pool: object) -> bool:
|
||||
await cur.executemany(sql_insert_RAWDATA, batch)
|
||||
await conn.commit()
|
||||
|
||||
logging.info(f"Completed batch {i//BATCH_SIZE + 1}/{(len(matrice_valori)-1)//BATCH_SIZE + 1}")
|
||||
logger.info(f"Completed batch {i//BATCH_SIZE + 1}/{(len(matrice_valori)-1)//BATCH_SIZE + 1}")
|
||||
|
||||
logging.info("Data loaded.")
|
||||
logger.info("Data loaded.")
|
||||
rc = True
|
||||
break
|
||||
except Exception as e:
|
||||
await conn.rollback()
|
||||
logging.error(f"Error: {e}.")
|
||||
logger.error(f"Error: {e}.")
|
||||
logger.error(f"Matrice valori da inserire: {batch}.")
|
||||
|
||||
if e.args[0] == 1213: # Deadlock detected
|
||||
logging.warning(
|
||||
logger.warning(
|
||||
f"Deadlock detected, attempt {attempt + 1}/{cfg.max_retries}"
|
||||
)
|
||||
|
||||
@@ -95,7 +96,7 @@ async def load_data(cfg: object, matrice_valori: list, pool: object) -> bool:
|
||||
await asyncio.sleep(delay)
|
||||
continue
|
||||
else:
|
||||
logging.error("Max retry attempts reached for deadlock")
|
||||
logger.error("Max retry attempts reached for deadlock")
|
||||
raise
|
||||
return rc
|
||||
|
||||
@@ -120,10 +121,10 @@ async def update_status(cfg: object, id: int, status: str, pool: object) -> None
|
||||
"""
|
||||
)
|
||||
await conn.commit()
|
||||
logging.info(f"Status updated id {id}.")
|
||||
logger.info(f"Status updated id {id}.")
|
||||
except Exception as e:
|
||||
await conn.rollback()
|
||||
logging.error(f"Error: {e}")
|
||||
logger.error(f"Error: {e}")
|
||||
|
||||
|
||||
async def unlock(cfg: object, id: int, pool: object) -> None:
|
||||
@@ -143,10 +144,10 @@ async def unlock(cfg: object, id: int, pool: object) -> None:
|
||||
f"update {cfg.dbrectable} set locked = 0 where id = {id}"
|
||||
)
|
||||
await conn.commit()
|
||||
logging.info(f"id {id} unlocked.")
|
||||
logger.info(f"id {id} unlocked.")
|
||||
except Exception as e:
|
||||
await conn.rollback()
|
||||
logging.error(f"Error: {e}")
|
||||
logger.error(f"Error: {e}")
|
||||
|
||||
|
||||
async def get_matlab_cmd(cfg: object, unit: str, tool: str, pool: object) -> tuple:
|
||||
@@ -172,4 +173,4 @@ async def get_matlab_cmd(cfg: object, unit: str, tool: str, pool: object) -> tup
|
||||
where t.name = "{tool}" and u.name = "{unit}"''')
|
||||
return cur.fetchone()
|
||||
except Exception as e:
|
||||
logging.error(f"Error: {e}")
|
||||
logger.error(f"Error: {e}")
|
||||
|
||||
Reference in New Issue
Block a user