Skip to content
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
5 changes: 5 additions & 0 deletions backend/kernelCI_app/constants/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@

PRODUCTION_HOST = "https://dashboard.kernelci.org"
STAGING_HOST = "https://staging.dashboard.kernelci.org"

# Timeouts in seconds
REQUESTS_TIMEOUT_UPLOAD_IN_SECONDS = 30
REQUESTS_TIMEOUT_WEBHOOK_IN_SECONDS = 10
REQUESTS_TIMEOUT_FETCH_IN_SECONDS = 30
5 changes: 4 additions & 1 deletion backend/kernelCI_app/helpers/discordWebhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
get_notification_cache,
set_notification_cache,
)
from kernelCI_app.constants.general import REQUESTS_TIMEOUT_WEBHOOK_IN_SECONDS
from kernelCI_app.helpers.logger import log_message

# For more information on discord webhook structure, visit
Expand Down Expand Up @@ -97,7 +98,9 @@ def send_discord_notification(
data["embeds"] = embeds

try:
result = requests.post(url=url, json=data)
result = requests.post(
url=url, json=data, timeout=REQUESTS_TIMEOUT_WEBHOOK_IN_SECONDS
)
result.raise_for_status()
except requests.HTTPError as e:
log_message(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any, Literal, Optional

import requests
from kernelCI_app.constants.general import REQUESTS_TIMEOUT_UPLOAD_IN_SECONDS
from kernelCI_app.constants.ingester import (
CACHE_LOGS_SIZE_LIMIT,
LOGEXCERPT_THRESHOLD,
Expand Down Expand Up @@ -47,7 +48,12 @@ def upload_logexcerpt(logexcerpt: str, id: str) -> str:
}
files = {"file0": ("logexcerpt.txt.gz", f), "path": f"logexcerpt/{id}"}
try:
r = requests.post(UPLOAD_URL, headers=hdr, files=files)
r = requests.post(
UPLOAD_URL,
headers=hdr,
files=files,
timeout=REQUESTS_TIMEOUT_UPLOAD_IN_SECONDS,
)
except Exception as e:
logger.error("Error uploading logexcerpt for %s: %s", id, e)
os.remove(logexcerpt_filename)
Expand Down
3 changes: 2 additions & 1 deletion backend/kernelCI_app/views/logDownloaderView.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from rest_framework.views import APIView

import requests
from kernelCI_app.constants.general import REQUESTS_TIMEOUT_FETCH_IN_SECONDS
from kernelCI_app.constants.localization import ClientStrings
from kernelCI_app.helpers.errorHandling import create_api_error_response
from kernelCI_app.typeModels.logDownloader import (
Expand All @@ -17,7 +18,7 @@

def scrape_log_data(url):
try:
response = requests.get(url)
response = requests.get(url, timeout=REQUESTS_TIMEOUT_FETCH_IN_SECONDS)
response.raise_for_status()

soup = BeautifulSoup(response.content, "html.parser")
Expand Down
Loading