Skip to content

Commit

Permalink
added an service indicater
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Hanke committed Dec 10, 2024
1 parent 1b74bd5 commit 98a1b46
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
18 changes: 17 additions & 1 deletion ckanext/fuseki/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8

from ckanext.fuseki.backend import get_graph
import re, os
import re, os, requests


# Retrieve the value of a configuration option
Expand All @@ -13,6 +13,22 @@ def common_member(a, b):
return any(i in b for i in a)


def fuseki_service_available():
url = os.environ.get("CKANINI__CKANEXT__FUSEKI__URL", "")
if not url:
return False # If EXTRACT_URL is not set, return False
try:
# Perform a HEAD request (lightweight check) to see if the service responds
response = requests.head(url, timeout=5, verify=False)
if (200 <= response.status_code < 400) or response.status_code == 405:
return True # URL is reachable and returns a valid status code
else:
return False # URL is reachable but response status is not valid
except requests.RequestException as e:
# If there's any issue (timeout, connection error, etc.)
return False


def fuseki_show_tools(resource):
from ckanext.fuseki.logic.action import DEFAULT_FORMATS

Expand Down
41 changes: 30 additions & 11 deletions ckanext/fuseki/templates/fuseki/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,36 @@ <h2 class="hide-heading">{{ _('Fuseki') }}</h2>
<div id="ajax-status" data-module="fuseki">
<form class="add-to-group" method="post">
{{ h.csrf_input() }}
<div class="row m-0 gx-3 gy-2align-items-center">
<button class="col-auto me-2 btn btn-secondary" name="create/update" type="submit">
<i class="fa fa-refresh"></i> {{ _('Create/Update') }}
</button>
<button class="col-auto me-2 btn btn-danger invisible" name="delete" type="submit">
<i class="fa fa-trash"></i> {{ _('Delete') }}
</button>
<a class="col-auto mr-2 btn btn-primary mb-0 invisible" name="query"
href="{{ h.fuseki_query_url(pkg_dict)|safe }}" role="button">
<i class="fa fa-play"></i> {{ _('Query') }}
</a>
<div class="col-12 d-flex align-items-center justify-content-between">
<div class="d-flex align-items-center">
<button class="col-auto me-2 btn btn-secondary {% if not
service_status %}disabled{% endif %}" name="create/update" type="submit">
<i class="fa fa-refresh"></i> {{ _('Create/Update') }}
</button>
<button class="col-auto me-2 btn btn-danger invisible" name="delete" type="submit">
<i class="fa fa-trash"></i> {{ _('Delete') }}
</button>
<a class="col-auto mr-2 btn btn-primary mb-0 invisible" name="query"
href="{{ h.fuseki_query_url(pkg_dict)|safe }}" role="button">
<i class="fa fa-play"></i> {{ _('Query') }}
</a>
</div>
<!-- Status Indicator Section -->
<style>
.indicator {
width: 20px;
height: 20px;
border-radius: 50%;
background-color: red;
/* Default: Service unavailable */
}
</style>
<div class="d-flex align-items-center">
<div id="service-indicator" class="indicator" data-bs-toggle="tooltip"
title="{{ _('The status of the service (Green means available, Red means unavailable)') }}" {% if
service_status %} style="background-color: green;" {% endif %}>
</div>
</div>
</div>
<hr class="">
{% if status.metadata is defined %}
Expand Down
3 changes: 2 additions & 1 deletion ckanext/fuseki/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ckan.lib.helpers as core_helpers
import ckan.lib.base as base
from flask import request
from ckanext.fuseki.helpers import fuseki_query_url
from ckanext.fuseki.helpers import fuseki_query_url, fuseki_service_available
from ckanext.fuseki.backend import Reasoners

log = __import__("logging").getLogger(__name__)
Expand Down Expand Up @@ -68,6 +68,7 @@ def get(self, id: str):
"pkg_dict": pkg_dict,
"resources": pkg_dict["resources"],
"status": status,
"service_status": fuseki_service_available(),
"reasoners": Reasoners.choices(),
},
)
Expand Down

0 comments on commit 98a1b46

Please sign in to comment.