Skip to content

Commit

Permalink
Feature/report generation timeout (1.10) (#1643)
Browse files Browse the repository at this point in the history
Signed-off-by: ammar <[email protected]>
Co-authored-by: ammar92 <[email protected]>
  • Loading branch information
dekkers and ammar92 authored Aug 22, 2023
1 parent 29f6630 commit 8ec7100
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions rocky/rocky/keiko.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ class GeneratingReportFailed(ReportException):


class KeikoClient:
def __init__(self, base_uri: str):
def __init__(self, base_uri: str, timeout: int = 60):
self.session = requests.Session()
self._base_uri = base_uri
self._timeout = timeout

def generate_report(self, template: str, data: Dict, glossary: str) -> str:
try:
Expand All @@ -50,9 +51,9 @@ def generate_report(self, template: str, data: Dict, glossary: str) -> str:
return res.json()["report_id"]

def get_report(self, report_id: str) -> BinaryIO:
# try max 15 times to get the report, 1 second interval
# try retrieving a report with a configured timeout
try:
for _ in range(15):
for _ in range(self._timeout):
time.sleep(1)
res = self.session.get(f"{self._base_uri}/reports/{report_id}.keiko.pdf")

Expand All @@ -73,7 +74,7 @@ def health(self) -> ServiceHealth:
return ServiceHealth.parse_obj(res.json())


keiko_client = KeikoClient(settings.KEIKO_API)
keiko_client = KeikoClient(settings.KEIKO_API, settings.KEIKO_REPORT_TIMEOUT)


class ReportsService:
Expand Down
8 changes: 4 additions & 4 deletions rocky/rocky/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

from rocky.otel import OpenTelemetryHelper

env = environ.Env(
DEBUG=(bool, False),
)
env = environ.Env()

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -49,9 +47,11 @@
BYTES_PASSWORD = env("BYTES_PASSWORD", default="")

KEIKO_API = env.url("KEIKO_API", "").geturl()
# Report generation timeout in seconds
KEIKO_REPORT_TIMEOUT = env.int("KEIKO_REPORT_TIMEOUT", 60)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env("DEBUG")
DEBUG = env.bool("DEBUG", False)

# Make sure this header can never be set by an attacker, see also the security
# warning at https://docs.djangoproject.com/en/4.2/howto/auth-remote-user/
Expand Down

0 comments on commit 8ec7100

Please sign in to comment.