forked from GithubBackups/healthchecks
Move timer call to api
This commit is contained in:
parent
9ad5571b8a
commit
3c57e4026a
@ -5,4 +5,5 @@ from hc.api import views
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^ping/([\w-]+)/$', views.ping, name="hc-ping"),
|
url(r'^ping/([\w-]+)/$', views.ping, name="hc-ping"),
|
||||||
url(r'^ping/([\w-]+)$', views.ping, name="hc-ping"),
|
url(r'^ping/([\w-]+)$', views.ping, name="hc-ping"),
|
||||||
|
url(r'^status/([\w-]+)/$', views.status, name="hc-status"),
|
||||||
]
|
]
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
from django.contrib.humanize.templatetags.humanize import naturaltime
|
||||||
from django.http import HttpResponse, HttpResponseBadRequest
|
from django.http import HttpResponse, HttpResponseBadRequest
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
@ -17,3 +20,23 @@ def ping(request, code):
|
|||||||
check.save()
|
check.save()
|
||||||
|
|
||||||
return HttpResponse("OK")
|
return HttpResponse("OK")
|
||||||
|
|
||||||
|
|
||||||
|
def status(request, code):
|
||||||
|
response = {
|
||||||
|
"last_ping": None,
|
||||||
|
"last_ping_human": None,
|
||||||
|
"secs_to_alert": None
|
||||||
|
}
|
||||||
|
|
||||||
|
check = Check.objects.get(code=code)
|
||||||
|
|
||||||
|
if check.last_ping and check.alert_after:
|
||||||
|
response["last_ping"] = check.last_ping.isoformat()
|
||||||
|
response["last_ping_human"] = naturaltime(check.last_ping)
|
||||||
|
|
||||||
|
duration = check.alert_after - timezone.now()
|
||||||
|
response["secs_to_alert"] = int(duration.total_seconds())
|
||||||
|
|
||||||
|
return HttpResponse(json.dumps(response),
|
||||||
|
content_type="application/javascript")
|
||||||
|
@ -11,5 +11,4 @@ urlpatterns = [
|
|||||||
url(r'^pricing/$', views.pricing, name="hc-pricing"),
|
url(r'^pricing/$', views.pricing, name="hc-pricing"),
|
||||||
url(r'^docs/$', views.docs, name="hc-docs"),
|
url(r'^docs/$', views.docs, name="hc-docs"),
|
||||||
url(r'^about/$', views.about, name="hc-about"),
|
url(r'^about/$', views.about, name="hc-about"),
|
||||||
url(r'^welcome/timer/$', views.welcome_timer, name="hc-welcome-timer"),
|
|
||||||
]
|
]
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
import json
|
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.humanize.templatetags.humanize import naturaltime
|
from django.http import HttpResponseForbidden
|
||||||
from django.http import HttpResponse, HttpResponseForbidden
|
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
@ -52,27 +48,8 @@ def about(request):
|
|||||||
return render(request, "about.html", {"page": "about"})
|
return render(request, "about.html", {"page": "about"})
|
||||||
|
|
||||||
|
|
||||||
def welcome_timer(request):
|
|
||||||
code = request.session["welcome_code"]
|
|
||||||
|
|
||||||
check = Check.objects.get(code=code)
|
|
||||||
if check.last_ping and check.alert_after:
|
|
||||||
duration = check.alert_after - timezone.now()
|
|
||||||
response = {
|
|
||||||
"last_ping": check.last_ping.isoformat(),
|
|
||||||
"last_ping_human": naturaltime(check.last_ping),
|
|
||||||
"timer": int(duration.total_seconds())
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
response = {"last_ping": None, "timer": None}
|
|
||||||
|
|
||||||
return HttpResponse(json.dumps(response),
|
|
||||||
content_type="application/javascript")
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def checks(request):
|
def checks(request):
|
||||||
|
|
||||||
checks = Check.objects.filter(user=request.user).order_by("created")
|
checks = Check.objects.filter(user=request.user).order_by("created")
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
|
|
||||||
|
var code = $("#check-code").text();
|
||||||
var url = $("#pitch-url").text();
|
var url = $("#pitch-url").text();
|
||||||
var lastPing = null;
|
var lastPing = null;
|
||||||
var lastPingHuman = null;
|
var lastPingHuman = null;
|
||||||
@ -10,10 +11,10 @@ $(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function checkLastPing() {
|
function checkLastPing() {
|
||||||
$.getJSON("/welcome/timer/", function(data) {
|
$.getJSON("/status/" + code + "/", function(data) {
|
||||||
if (data.last_ping != lastPing) {
|
if (data.last_ping != lastPing) {
|
||||||
lastPing = data.last_ping;
|
lastPing = data.last_ping;
|
||||||
$("#timer").data("timer", data.timer);
|
$("#timer").data("timer", data.secs_to_alert);
|
||||||
}
|
}
|
||||||
|
|
||||||
var lph = data.last_ping_human;
|
var lph = data.last_ping_human;
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div id="welcome-status" class="col-sm-6">
|
<div id="welcome-status" class="col-sm-6">
|
||||||
<h2>Status
|
<h2>Status
|
||||||
<small>{{ check.code }}</small>
|
<small id="check-code">{{ check.code }}</small>
|
||||||
</h2>
|
</h2>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user