Skip to content

Commit

Permalink
refactor:cache rebuilding for better readability.
Browse files Browse the repository at this point in the history
Updated formatting in task output for improved clarity and adjusted cache timeout to 2 seconds. Ensured consistent error messages and streamlined code structure.
  • Loading branch information
hareshkainthdbt committed Jan 23, 2025
1 parent 4f7e521 commit 6849de8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 7 additions & 4 deletions app/cache/manage_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ def rebuild_cache():
try:
start = time.time()
clear_all_documents()
config = SearchDocumentConfig(search_query="", timeout=1)
Legislation().build_cache(config)
config = SearchDocumentConfig(search_query="", timeout=2)
PublicGateway().build_cache(config)
Legislation().build_cache(config)
end = time.time()
return {"message": "rebuilt cache", "duration": round(end - start, 2)}
return {
"message": "rebuilt cache",
"duration": round(end - start, 2),
}
except Exception as e:
return {"message": f"error clearing documents: {e}"}
return {"message": f"error building cache data: {e}"}
11 changes: 6 additions & 5 deletions celery_worker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ def rebuild_cache():
PublicGateway().build_cache(config)
Legislation().build_cache(config)
end = time.time()
message = {
"message": "rebuilt cache",
"duration": round(end - start, 2),
}
print(message)
print(
{
"message": "rebuilt cache",
"duration": round(end - start, 2),
}
)
except Exception as e:
message = {"message": f"error building cache data: {e}"}
print(message)

0 comments on commit 6849de8

Please sign in to comment.