add a timestamp to deployment json (#5114)
This commit is contained in:
parent
f5a964da3e
commit
882ae03943
|
@ -16,6 +16,7 @@ class Variable(models.Model):
|
|||
value = models.TextField(verbose_name=_('value'),
|
||||
blank=True,
|
||||
help_text=_('start with [ or { for a JSON document'))
|
||||
last_update_timestamp = models.DateTimeField(auto_now=True, null=True)
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
|
@ -42,6 +43,7 @@ class ServiceBase(models.Model):
|
|||
|
||||
last_operational_check_timestamp = models.DateTimeField(null=True)
|
||||
last_operational_success_timestamp = models.DateTimeField(null=True)
|
||||
last_update_timestamp = models.DateTimeField(auto_now=True, null=True)
|
||||
|
||||
def is_operational(self):
|
||||
return (self.last_operational_success_timestamp is not None and
|
||||
|
@ -56,7 +58,7 @@ class ServiceBase(models.Model):
|
|||
self.last_operational_success_timestamp = once_now
|
||||
except (urllib2.URLError, urllib2.HTTPError):
|
||||
pass
|
||||
self.save()
|
||||
self.save(update_fields=('last_operational_check_timestamp', 'last_operational_success_timestamp'))
|
||||
|
||||
def wants_frequent_checks(self):
|
||||
if self.last_operational_check_timestamp is None:
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import calendar
|
||||
import datetime
|
||||
import json
|
||||
import string
|
||||
|
||||
|
@ -6,6 +8,7 @@ from django.core.urlresolvers import reverse_lazy
|
|||
from django.http import HttpResponse
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||
from django.db.models import Max
|
||||
|
||||
from .models import Variable, Authentic, Wcs, AVAILABLE_SERVICES
|
||||
from . import forms, utils
|
||||
|
@ -134,7 +137,18 @@ def operational_check_view(request, service, slug, **kwargs):
|
|||
|
||||
def installed_services_json_view(request, **kwargs):
|
||||
response = HttpResponse(content_type='application/json')
|
||||
|
||||
timestamp = None
|
||||
for klass in [Variable] + AVAILABLE_SERVICES:
|
||||
ts = klass.objects.all().aggregate(Max('last_update_timestamp')
|
||||
).get('last_update_timestamp__max')
|
||||
if timestamp is None or (ts and ts > timestamp):
|
||||
timestamp = ts
|
||||
if timestamp is None:
|
||||
timestamp = datetime.datetime.now()
|
||||
|
||||
json.dump({
|
||||
'timestamp': calendar.timegm(timestamp.timetuple()),
|
||||
'services': [x.as_dict() for x in utils.get_installed_services()],
|
||||
'variables': dict(((v.name, v.json)
|
||||
for v in Variable.objects.all())),
|
||||
|
|
Loading…
Reference in New Issue