add logging and timeout to deployment gen
@@ -6,6 +6,7 @@ import pytz
from django.conf import settings
from django.shortcuts import get_object_or_404
from django.utils import timezone as djangotime
+from loguru import logger
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView
@@ -24,6 +25,8 @@ from .serializers import (
SiteSerializer,
)
+logger.configure(**settings.LOG_CONFIG)
+
class GetAddClients(APIView):
def get(self, request):
@@ -280,8 +283,8 @@ class GenerateAgent(APIView):
permission_classes = (AllowAny,)
def get(self, request, uid):
- import requests
import tempfile
+ import requests
from django.http import FileResponse
try:
@@ -319,12 +322,20 @@ class GenerateAgent(APIView):
headers = {"Content-type": "application/json"}
with tempfile.NamedTemporaryFile() as fp:
+ try:
r = requests.post(
settings.EXE_GEN_URL,
json=data,
headers=headers,
stream=True,
+ timeout=900,
)
+ except Exception as e:
+ logger.error(str(e))
+ return notify_error(
+ "Something went wrong. Check debug error log for exact error message"
+ )
+
with open(fp.name, "wb") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
