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)
|
rows = list(reader)
|
||||||
print(f"[INFO] {len(rows)} lignes lues dans le CSV")
|
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:
|
if args.truncate:
|
||||||
print("[INFO] Nettoyage des tables référençant servers")
|
print("[INFO] Nettoyage des tables référençant servers")
|
||||||
if not args.dry_run:
|
if not args.dry_run:
|
||||||
@ -121,7 +122,6 @@ def main():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sp = conn.begin_nested()
|
|
||||||
conn.execute(text("""
|
conn.execute(text("""
|
||||||
INSERT INTO servers
|
INSERT INTO servers
|
||||||
(hostname, fqdn, domain_ltd, os_family, os_version, machine_type,
|
(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,
|
(:hostname, :fqdn, :domain_ltd, :os_family, :os_version, :machine_type,
|
||||||
:etat, :site, :vcenter_vm_name, :responsable_nom, :patch_owner_details)
|
:etat, :site, :vcenter_vm_name, :responsable_nom, :patch_owner_details)
|
||||||
"""), params)
|
"""), params)
|
||||||
sp.commit()
|
|
||||||
inserted += 1
|
inserted += 1
|
||||||
if ip:
|
if ip:
|
||||||
ip_map.append((hostname, ip))
|
ip_map.append((hostname, ip))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
try: sp.rollback()
|
|
||||||
except Exception: pass
|
|
||||||
print(f" [ERR] {hostname}: {str(e)[:200]}")
|
print(f" [ERR] {hostname}: {str(e)[:200]}")
|
||||||
skipped += 1
|
skipped += 1
|
||||||
|
|
||||||
@ -153,6 +150,8 @@ def main():
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
print(f"[DONE] Inséré/mis à jour: {inserted} | Ignoré: {skipped}")
|
print(f"[DONE] Inséré/mis à jour: {inserted} | Ignoré: {skipped}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user