Use autocommit mode to persist inserts immediately
This commit is contained in:
parent
c6113bc537
commit
b72f1244dd
@ -57,7 +57,8 @@ def main():
|
||||
rows = list(reader)
|
||||
print(f"[INFO] {len(rows)} lignes lues dans le CSV")
|
||||
|
||||
with engine.begin() as conn:
|
||||
conn = engine.connect().execution_options(isolation_level="AUTOCOMMIT")
|
||||
try:
|
||||
if args.truncate:
|
||||
print("[INFO] Nettoyage des tables référençant servers")
|
||||
if not args.dry_run:
|
||||
@ -121,7 +122,6 @@ def main():
|
||||
continue
|
||||
|
||||
try:
|
||||
sp = conn.begin_nested()
|
||||
conn.execute(text("""
|
||||
INSERT INTO servers
|
||||
(hostname, fqdn, domain_ltd, os_family, os_version, machine_type,
|
||||
@ -130,13 +130,10 @@ def main():
|
||||
(:hostname, :fqdn, :domain_ltd, :os_family, :os_version, :machine_type,
|
||||
:etat, :site, :vcenter_vm_name, :responsable_nom, :patch_owner_details)
|
||||
"""), params)
|
||||
sp.commit()
|
||||
inserted += 1
|
||||
if ip:
|
||||
ip_map.append((hostname, ip))
|
||||
except Exception as e:
|
||||
try: sp.rollback()
|
||||
except Exception: pass
|
||||
print(f" [ERR] {hostname}: {str(e)[:200]}")
|
||||
skipped += 1
|
||||
|
||||
@ -153,6 +150,8 @@ def main():
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
finally:
|
||||
conn.close()
|
||||
print(f"[DONE] Inséré/mis à jour: {inserted} | Ignoré: {skipped}")
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user