Skip to content

Commit

Permalink
force queries to use cached BQM response within 10 mins of current time
Browse files Browse the repository at this point in the history
  • Loading branch information
kthare10 committed Aug 29, 2024
1 parent a38ffd9 commit 8404f87
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
#
# Author: Komal Thareja ([email protected])
from datetime import timedelta
from datetime import timedelta, datetime, timezone
from http.client import BAD_REQUEST

from fabric_cf.orchestrator.core.exceptions import OrchestratorException
Expand Down Expand Up @@ -65,6 +65,15 @@ def portalresources_get(graph_format: str, level: int = 1, force_refresh: bool =
start = handler.validate_lease_time(lease_time=start_date)
end = handler.validate_lease_time(lease_time=end_date)

# Check if 'start' is defined but 'end' is not
if start and not end:
now = datetime.now(timezone.utc)

# Check if the current time is within 10 minutes from 'start'
if now - start < timedelta(minutes=10):
# Reset start to None so as the cache is used
start = None

if start and end and (end - start) < timedelta(minutes=60):
raise OrchestratorException(http_error_code=BAD_REQUEST,
message="Time range should be at least 60 minutes long!")
Expand Down Expand Up @@ -116,6 +125,15 @@ def resources_get(level: int = 1, force_refresh: bool = False, start_date: str =
start = handler.validate_lease_time(lease_time=start_date)
end = handler.validate_lease_time(lease_time=end_date)

# Check if 'start' is defined but 'end' is not
if start and not end:
now = datetime.now(timezone.utc)

# Check if the current time is within 10 minutes from 'start'
if now - start < timedelta(minutes=10):
# Reset start to None so as the cache is used
start = None

if start and end and (end - start) < timedelta(minutes=60):
raise OrchestratorException(http_error_code=BAD_REQUEST,
message="Time range should be at least 60 minutes long!")
Expand Down

0 comments on commit 8404f87

Please sign in to comment.