Skip to content

Commit b440494

Browse files
committed
waiting for the view to be refreshed
1 parent a2cb3f9 commit b440494

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

functions-python/helpers/database.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,17 @@ def close_db_session(session, raise_exception: bool = False):
152152
raise error
153153

154154

155-
def refresh_materialized_view(session, view_name: str) -> bool:
155+
def refresh_materialized_view(session, view_name: str, concurrently=True) -> bool:
156156
"""
157157
Refresh Materialized view by name.
158158
@return: True if the view was refreshed successfully, False otherwise
159159
"""
160160
try:
161-
session.execute(text(f"REFRESH MATERIALIZED VIEW CONCURRENTLY {view_name}"))
161+
session.execute(
162+
text(
163+
f"REFRESH MATERIALIZED VIEW {'CONCURRENTLY' if concurrently else ''} {view_name}"
164+
)
165+
)
162166
return True
163167
except Exception as error:
164168
logging.error(f"Error raised while refreshing view: {error}")

functions-python/operations_api/src/feeds_operations/impl/feeds_operations_impl.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ async def _update_feed(
151151
else update_request_feed.operational_status_action
152152
)
153153
session.add(feed)
154+
refreshed = refresh_materialized_view(session, t_feedsearch.name, False)
155+
logging.info(
156+
f"Materialized view {t_feedsearch.name} refreshed: {refreshed}"
157+
)
154158
session.commit()
155-
# Refresh the materialized view has to be done after the commit
156-
refresh_materialized_view(session, t_feedsearch.name)
157159
logging.info(
158160
f"Feed ID: {update_request_feed.id} updated successfully with the following changes: "
159161
f"{diff.values()}"

0 commit comments

Comments
 (0)