Skip to content

Commit

Permalink
waiting for the view to be refreshed
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamez committed Dec 5, 2024
1 parent a2cb3f9 commit b440494
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions functions-python/helpers/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()}"
Expand Down

0 comments on commit b440494

Please sign in to comment.