Browse Source

better logging monitoring

master
Mohsen Taba 1 month ago
parent
commit
c588026d8b
  1. 2
      .env.prod
  2. 21
      apps/course/services/web_egress.py

2
.env.prod

@ -27,7 +27,7 @@ ONLINE_CLASS_FRONTEND_DOMAIN="meet.imamjavad.online"
FCM_API_KEY=""
ONLINE_CLASS_WEB_EGRESS_ENABLED=True
ONLINE_CLASS_WEB_EGRESS_SERVICE_URL=https://imamjavad.nwhco.ir/chat
ONLINE_CLASS_WEB_EGRESS_SERVICE_URL=http://88.99.212.243:8020/chat
ONLINE_CLASS_WEB_EGRESS_SERVICE_TOKEN=9b7f2b3e6c1a4d8f9e2c7a1b5d3f6e8c
ONLINE_CLASS_WEB_EGRESS_CALLBACK_TOKEN=3f9c7e1a8d2b6c4f5a1e9d7b2c8f6a3e
ONLINE_CLASS_WEB_EGRESS_TIMEOUT=20

21
apps/course/services/web_egress.py

@ -1,11 +1,14 @@
from __future__ import annotations
import logging
from typing import Any, Dict, Optional
import requests
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
logger = logging.getLogger(__name__)
class WebEgressError(Exception):
def __init__(
@ -64,15 +67,23 @@ class WebEgressClient:
if self.service_token:
headers["Authorization"] = f"Bearer {self.service_token}"
request_url = f"{self.base_url}{path}"
try:
response = requests.request(
method,
f"{self.base_url}{path}",
request_url,
headers=headers,
timeout=self.timeout,
**kwargs,
)
except requests.RequestException as exc:
logger.exception(
"[WebEgressClient] Request failed method=%s url=%s error=%s",
method,
request_url,
str(exc),
)
raise WebEgressError("Failed to reach WebEgress service.") from exc
data = self._safe_json(response)
@ -83,6 +94,14 @@ class WebEgressClient:
or response.text
or "WebEgress service request failed."
)
logger.error(
"[WebEgressClient] Non-success response method=%s url=%s status=%s message=%s payload=%s",
method,
request_url,
response.status_code,
message,
data,
)
raise WebEgressError(
message,
status_code=response.status_code,

Loading…
Cancel
Save