From c1f4017cb4472ce7028ed15c6388ba722ea2955d Mon Sep 17 00:00:00 2001 From: Jan Dobes Date: Mon, 19 Aug 2024 14:58:35 +0200 Subject: [PATCH] fix(vmaas-sync): make sure event row is commited before sending it in kafka messages --- vmaas_sync/vmaas_sync.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vmaas_sync/vmaas_sync.py b/vmaas_sync/vmaas_sync.py index 59892adfb..4d10f8b32 100644 --- a/vmaas_sync/vmaas_sync.py +++ b/vmaas_sync/vmaas_sync.py @@ -81,6 +81,7 @@ def _delete_old_recalc_events(conn): """delete from recalc_event where created < now() - interval '30 days' returning id""", ) deleted = cur.fetchall() + conn.commit() LOGGER.info("Deleted %s old recalc events older than 30 days", len(deleted)) @@ -92,6 +93,7 @@ def _save_recalc_event(conn, repos: dict[str, list[str]]): (json.dumps(repos),), ) ret = cur.fetchone() + conn.commit() return ret[0] @@ -316,10 +318,10 @@ def re_evaluate_systems(): LOGGER.info("Fetched 0 repos from VMaaS, skipping repo-based re-evaluation") return + LOGGER.info("Re-evaluating in repo-based mode") + _delete_old_recalc_events(conn) + event_id = _save_recalc_event(conn, updated_repos) with NamedCursor(conn) as cur: - LOGGER.info("Re-evaluating in repo-based mode") - _delete_old_recalc_events(conn) - event_id = _save_recalc_event(conn, updated_repos) _select_repo_based_inventory_ids(cur, list(updated_repos)) loop = asyncio.get_event_loop()