load csv async

This commit is contained in:
2025-05-11 11:20:18 +02:00
parent 1dfb1a2efa
commit cbcadbf015
4 changed files with 27 additions and 36 deletions

View File

@@ -32,7 +32,7 @@ class Config:
self.dbuser = c.get("db", "user")
self.dbpass = c.get("db", "password")
self.dbname = c.get("db", "dbName")
self.dbschema = c.get("db", "dbSchema")
#self.dbschema = c.get("db", "dbSchema")
self.dbusertable = c.get("db", "userTableName")
self.dbrectable = c.get("db", "recTableName")
self.dbrawdata = c.get("db", "rawTableName")

View File

@@ -8,6 +8,9 @@ CSV_RECEIVED = 0
DATA_LOADED = 1
DATA_ELABORATED = 2
timestamp_cols = ['inserted_at', 'loaded_at', 'elaborated_at']
def load_data(cfg: object, matrice_valori: list) -> bool :
sql_insert_RAWDATA = f'''
INSERT IGNORE INTO {cfg.dbname}.{cfg.dbrawdata} (
@@ -42,8 +45,9 @@ def update_status(cfg: object, id: int, status: int) -> None:
with connetti_db(cfg) as conn:
cur = conn.cursor()
try:
cur.execute(f'update {cfg.dbname}.{cfg.dbrectable} set locked = 0, status = {status} where id = {id}')
cur.execute(f'update {cfg.dbname}.{cfg.dbrectable} set locked = 0, status = {status}, {timestamp_cols[status]} = now() where id = {id}')
conn.commit()
logging.info("Status updated.")
except Exception as e:
conn.rollback()
logging.error(f'Error: {e}')