From b4404942c96f1df848216600cb2f9baa85a4d136 Mon Sep 17 00:00:00 2001 From: David Gamez Diaz <1192523+davidgamez@users.noreply.github.com> Date: Wed, 4 Dec 2024 21:47:24 -0500 Subject: [PATCH] waiting for the view to be refreshed --- functions-python/helpers/database.py | 8 ++++++-- .../src/feeds_operations/impl/feeds_operations_impl.py | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/functions-python/helpers/database.py b/functions-python/helpers/database.py index 92a31e7db..eccbaed0e 100644 --- a/functions-python/helpers/database.py +++ b/functions-python/helpers/database.py @@ -152,13 +152,17 @@ def close_db_session(session, raise_exception: bool = False): raise error -def refresh_materialized_view(session, view_name: str) -> bool: +def refresh_materialized_view(session, view_name: str, concurrently=True) -> bool: """ Refresh Materialized view by name. @return: True if the view was refreshed successfully, False otherwise """ try: - session.execute(text(f"REFRESH MATERIALIZED VIEW CONCURRENTLY {view_name}")) + session.execute( + text( + f"REFRESH MATERIALIZED VIEW {'CONCURRENTLY' if concurrently else ''} {view_name}" + ) + ) return True except Exception as error: logging.error(f"Error raised while refreshing view: {error}") diff --git a/functions-python/operations_api/src/feeds_operations/impl/feeds_operations_impl.py b/functions-python/operations_api/src/feeds_operations/impl/feeds_operations_impl.py index 611193b51..712e4431d 100644 --- a/functions-python/operations_api/src/feeds_operations/impl/feeds_operations_impl.py +++ b/functions-python/operations_api/src/feeds_operations/impl/feeds_operations_impl.py @@ -151,9 +151,11 @@ async def _update_feed( else update_request_feed.operational_status_action ) session.add(feed) + refreshed = refresh_materialized_view(session, t_feedsearch.name, False) + logging.info( + f"Materialized view {t_feedsearch.name} refreshed: {refreshed}" + ) session.commit() - # Refresh the materialized view has to be done after the commit - refresh_materialized_view(session, t_feedsearch.name) logging.info( f"Feed ID: {update_request_feed.id} updated successfully with the following changes: " f"{diff.values()}"