-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
force queries to use cached BQM response within 10 mins of current time
- Loading branch information
Showing
1 changed file
with
19 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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!") | ||
|
@@ -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!") | ||
|