Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report generation timeout #1640

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -47,9 +45,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