Changeset View
Changeset View
Standalone View
Standalone View
swh/web/misc/urls.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import json | import json | ||||
import requests | import requests | ||||
import sentry_sdk | |||||
from django.conf.urls import url, include | from django.conf.urls import url, include | ||||
from django.contrib.staticfiles import finders | from django.contrib.staticfiles import finders | ||||
from django.http import HttpResponse | from django.http import HttpResponse | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
from swh.web.common import service | from swh.web.common import service | ||||
from swh.web.config import get_config | from swh.web.config import get_config | ||||
Show All 11 Lines | |||||
def _stat_counters(request): | def _stat_counters(request): | ||||
stat = service.stat_counters() | stat = service.stat_counters() | ||||
url = get_config()['history_counters_url'] | url = get_config()['history_counters_url'] | ||||
stat_counters_history = 'null' | stat_counters_history = 'null' | ||||
if url: | if url: | ||||
try: | try: | ||||
response = requests.get(url, timeout=5) | response = requests.get(url, timeout=5) | ||||
stat_counters_history = response.text | stat_counters_history = response.text | ||||
except Exception: | except Exception as exc: | ||||
pass | sentry_sdk.capture_exception(exc) | ||||
json_data = '{"stat_counters": %s, "stat_counters_history": %s}' % ( | json_data = '{"stat_counters": %s, "stat_counters_history": %s}' % ( | ||||
json.dumps(stat), stat_counters_history) | json.dumps(stat), stat_counters_history) | ||||
return HttpResponse(json_data, content_type='application/json') | return HttpResponse(json_data, content_type='application/json') | ||||
urlpatterns = [ | urlpatterns = [ | ||||
url(r'^', include('swh.web.misc.coverage')), | url(r'^', include('swh.web.misc.coverage')), | ||||
url(r'^jslicenses/$', _jslicenses, name='jslicenses'), | url(r'^jslicenses/$', _jslicenses, name='jslicenses'), | ||||
Show All 34 Lines |